473,387 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

fstream error on SUN

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

Nov 8 '05 #1
3 2603
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

Nov 8 '05 #2
Thanks. The problem gone away by removing the using namespace std line.

Nov 9 '05 #3

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

Nov 9 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Newsgroup - Ann | last post by:
The fstream is supposed to be a replacement of the stdio.h and the exception is supposed to be a replacement of the return error code. So how do I replace my old codes of the style: if (output =...
6
by: Armando | last post by:
Hallo ! I habe some error in my programm,because i use <fstream.h>,I want to use <fstream> but i donīt know which fonctions i must modify in my program ? Thanks you for your help. Armando.
6
by: David Briggs | last post by:
I am using MS VC++ 6.0 with MFC I have a simple class: #include <fstream.h> class Data { public: CString WriteStr(); Data();
1
by: Pasacco | last post by:
Dear When I was installing a software written in C++, following error message appeared, in my platform (gcc version 3.2.2 20030222 Red Hat Linux 3.2.2-5). I guess that this problem might be...
3
by: Catweasel | last post by:
I'm new to C++ and have been chucked in at the deep-end. I have a C++ console app that works fine. All I want to do is write to file however as soon as I include the fstream library and try to...
9
by: Someonekicked | last post by:
In my program, I need to open multiple files, and I wont know till after the program execution how many of them (user will enter that value). So I am using a vector of fstream. I am using fstream...
1
by: MForey | last post by:
I'm attempting to create a program that uses fstream objects to read/write to files. However, it is currently balky at best. The fstream.write call doesn't return an error, but the modified data...
6
by: wiso | last post by:
My problem is this (from: http://www.cplusplus.com/ref/iostream/fstream/open.html) #include <fstream> using namespace std; int main() { fstream f;
6
by: Gaijinco | last post by:
Should this do something? #include <fstream> #include <string> int main() { std::fstream filestr ("test.txt", std::fstream::in | std::fstream::out); std::string s="";
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.