Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > fstream error on SUN

Reply
Thread Tools

fstream error on SUN

 
 
ratzeel
Guest
Posts: n/a
 
      11-08-2005
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

 
Reply With Quote
 
 
 
 
deane_gavin@hotmail.com
Guest
Posts: n/a
 
      11-08-2005
ratzeel wrote:
> 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-lit....html#faq-27.4

Gavin Deane

 
Reply With Quote
 
 
 
 
ratzeel
Guest
Posts: n/a
 
      11-09-2005
Thanks. The problem gone away by removing the using namespace std line.

 
Reply With Quote
 
deane_gavin@hotmail.com
Guest
Posts: n/a
 
      11-09-2005

ratzeel wrote:
> 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-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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sun Updates Sun Java Availability Suite, Adds Sun Cluster Advanced Edition for Oracle Real Application Clusters Deployments technology_post@yahoo.com Java 0 04-05-2006 04:29 AM
what is different between <fstream.h> and <fstream>MS VC++ Armando C++ 6 01-29-2004 09:01 AM
[SUN] Take Sun Security Course and Get a Digital Camera Joan MacEachern Java 0 10-01-2003 03:14 PM
Sun ONE, The xerces problem (Sun One Oh my) Roy Benjamin Java 3 07-23-2003 08:32 PM
[SUN] Discounts from Sun Developer Network bookstore James Cham Java 0 07-21-2003 03:24 PM



Advertisments