fstream error on SUN

R

ratzeel

The following snippet code throws an error while compiling on SUN os..

Any idea how to resolve this...

#include <iostream.h>
#include <fstream.h>
#include <math.h>
#include <algorithm>
using namespace std;

..........
..........

fstream fp;
fp.open((*it).c_str(),ios::in); // Line 223
.......
.......
fp.open((*it).c_str(),ios::in); // Line 345


The error is as follows:

line 223: Error: The name fstream is ambiguous, fstream and
std::fstream.
line 345: Error: The name ios is ambiguous, ios and std::ios.

TIA, ratzeel
 
D

deane_gavin

ratzeel said:
The following snippet code throws an error while compiling on SUN os..

Any idea how to resolve this...

#include <iostream.h>

Not a standard C++ header
#include <fstream.h>

Not a standard C++ header
#include <math.h>
#include <algorithm>

These two are OK
using namespace std;

.........
.........

fstream fp;
fp.open((*it).c_str(),ios::in); // Line 223
......
......
fp.open((*it).c_str(),ios::in); // Line 345


The error is as follows:

line 223: Error: The name fstream is ambiguous, fstream and
std::fstream.
line 345: Error: The name ios is ambiguous, ios and std::ios.

TIA, ratzeel

http://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.4

Gavin Deane
 
D

deane_gavin

ratzeel said:
Thanks. The problem gone away by removing the using namespace std line.

A summary of your problem is:

#include <iostream.h>
#include <fstream.h>

using namespace std;

<some code using the names fstream and ios>

line 223: Error: The name fstream is ambiguous, fstream and
std::fstream.
line 345: Error: The name ios is ambiguous, ios and std::ios.

Do you understand why removing
using namespace std;
makes the problem go away?
http://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.5

You could equally well make the problem go away by including the
standard <iostream> and <fstream> headers instead of <iostream.h> and
<fstream.h>, as the FAQ I first pointed to suggests.
http://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.4

Your headers ending in .h are non-standard, which means that the next
compiler you use may or may not provide tham at all, and even if it
does, the contents may or may not be the same as what you are used to
using.

On the other hand, if you learn how to use the standard headers, you
will get identical functionality available on every conforming C++
compiler.

If you understand all that and you are happy with the non-standard .h
headers then that's fine. But bear in mind that this group discusses
standard C++ so you won't be able to get help here with code that
relies on your particular implementation of <iostream.h>

Gavin Deane
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top