Solved

C++ compiling error:C2872 ambiguous symbol

Posted on 2003-12-11
9
977 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

803 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