Connecting Tech Pros Worldwide Forums | Help | Site Map

fstream error on SUN

ratzeel
Guest
 
Posts: n/a
#1: Nov 8 '05
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


deane_gavin@hotmail.com
Guest
 
Posts: n/a
#2: Nov 8 '05

re: fstream error on SUN


ratzeel wrote:[color=blue]
> The following snippet code throws an error while compiling on SUN os..
>
> Any idea how to resolve this...
>
> #include <iostream.h>[/color]

Not a standard C++ header
[color=blue]
> #include <fstream.h>[/color]

Not a standard C++ header
[color=blue]
> #include <math.h>
> #include <algorithm>[/color]

These two are OK
[color=blue]
> 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[/color]

http://www.parashift.com/c++-faq-lit....html#faq-27.4

Gavin Deane

ratzeel
Guest
 
Posts: n/a
#3: Nov 9 '05

re: fstream error on SUN


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

deane_gavin@hotmail.com
Guest
 
Posts: n/a
#4: Nov 9 '05

re: fstream error on SUN



ratzeel wrote:[color=blue]
> Thanks. The problem gone away by removing the using namespace std line.[/color]

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-lit....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-lit....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

Closed Thread