Solved

C++ compiling error:C2872 ambiguous symbol

Posted on 2003-12-11
9
988 Views
Last Modified: 2010-04-01
When I'm using :
#include <iostream.h>
#include<fsteam.h>
#include<string>
using namespace std;

I'm getting this error:
error C2872: 'ostream' : ambiguous symbol

How can I solve it???

0
Comment
Question by:reemYaz
9 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 125 total points
ID: 9925344
>>How can I solve it???

Don't mix STL headers with non-standard headers:

#include <iostream>
#include<fsteam>
#include<string>
using namespace std;


0
 
LVL 9

Expert Comment

by:tinchos
ID: 9925352
Hi reemYaz,

Try replacing the includes with the standard ones (without the .h)

#include <iostream>
#include<fstream>
#include<string>
using namespace std;

Cheers!

Tincho
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 9926132
Also, <fstream> is mis-splelt as <fsteam>. You forgot to put an 'r' there.

Mayank.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 30

Expert Comment

by:Mayank S
ID: 9926140
Oh, Tinchos has put it right. By the way, do you need to include <iostream> if <fstream> is already included?
0
 
LVL 9

Expert Comment

by:tinchos
ID: 9927785
I'm not sure as code was not posted......

I just corrected the posted code........ lets hope that works for reemYaz

Tincho
0
 
LVL 11

Expert Comment

by:cup
ID: 9933603
iostream.h is for the old standard (V2), iostream is for the new standard (V3, STL).  Most systems have iostream.h and fstream.h for backward compatibility, and, as mentioned earlier, you shouldn't mix the two.
0
 

Expert Comment

by:MAYURNATH
ID: 9971266
#include <string> - is using the std namespace

#include <iostream.h> is not in namespace.

namespace concept is to avoid this type of problems.

if u write a function in on library , and another library also contains the same fucntion then u go for specifying a particualr libarary to a namespace.

u want to use <string> ostream then go like std::ostream and declare ur variable
u want to use <iostream.h> ostream then go like ostream and declare ur variable

In the above situation u have to avoid using namespace std;

the sample code is as follows :
#include <iostream.h>
#include <fstream.h>
#include <string>

int main(int argc, char* argv[])
{
      std::ostream    aStringStream ;
      ostream           aIOStream ;
      return 0;
}

i suppose this will clear the picture

thanx
0
 
LVL 9

Expert Comment

by:tinchos
ID: 10356425
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: jkr {http:#9925344}

Please leave any comments here within the next four days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question