Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ambiguous symbol 1

Status
Not open for further replies.

jubbles

Technical User
Nov 12, 2002
4
IE
Hi,
I developed code in UNIX which works fine, however when I try to use the code in MS visual C++, I get lots of errors. Some of these I have resolved, however the following error continues to confuse me. I have the following libraries.
#include<iostream>
#include<string.h>
#include&quot;string.h&quot;
#include<fstream.h>
#include<stdlib.h>

using namespace std;

However if I try to use cout I get an error saying &quot;error C2872: 'cout' : ambiguous symbol&quot;. I get a similar error whenever I use ifstream or ofstream. Why does this happen?
Thanks,

Jubbles Renoir
 
if you are not in the same file as you declare the namespace you will need to use std::cout

I belive this is all you should need. I dont usually use cout anymore except in quick console apps to do some mindless chores for me so I am not 100% on this.

Matt
 
Thanks,
I declared the namespace in the same file however, just for laughs, I tried prepending std:: to cout. That worked. However the folowing does not work:

ofstream output(fileNm);

This too is an ambigous symbol apparently. Using std:: here does not have the same affect as when used with cout. Any ideas??

Jubbles
 
Jubbles,

You are mixing the old stream library headers with the stl headers. They have the same class names in them. So if you want to use the stl classes then remove the header includes for the old stream library.

Good luck
-pete
 
In other words, you probably want:

#include<iostream>
#include<string>
#include<fstream>
#include<stdlib.h>

using namespace std;

...

To use the newer std library stuff, get rid of the &quot;.h&quot; stuff.
 
great, thats done the Job.
Thanks to all
 
Hi,

I am encountering this same problem and I tried the solution suggested -- putting &quot;std::&quot; in front of cout and cin. However I wind up getting a different error:

error C2679: binary '>>': no operator found which takes a right hand operand of tye 'std::string' (or there is no acceptable conversion)

My includes are as follows:
#include &quot;stdafx.h&quot;
#include <iostream>
#include <iomanip>
using namespace std;

Any help would be appreciated. The file I'm using, btw, is a solution from a training course that I took for my job last year. So it should compile fine, but Microsoft .NET is giving me headaches.

I'm expecting to possibly do some C++ programming this year on the job, and I want to make sure I can work well with Microsoft Visual C++.NET. That is the rationale for running this test.

Thanks in advance
Edward Curtis
U.S. Department of Energy
 
If you want to use the string class, you have to include the string header:

...
#include <iostream>
#include <iomanip>
#include <string>
...

You just got lucky (or unlucky actually) that the compiler recognized your string at all without the actual header.

Also, you should put std:: in front of cout, cin, string and everything else from the standard C++ headers, or you can keep the using namespace std; and not put in the std:: (I prefer putting std::). You don't have to do both.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top