• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2453
  • Last Modified:

error C2872: 'ifstream' : ambiguous symbol

I'm getting this error in my Visual C++ project when I compile:

c:\TYVCPROG\PROGRAMS\NIC2\nic.cpp(62) : error C2872: 'ifstream' : ambiguous symbol
Error executing cl.exe.

Here's the part of the files thats causing the problem:

#include <afx.h>
#include "spellAPI.h"
#include <string.h>
#include <fstream.h>
#include "Node.h"

//opens the text file for input as inDictFile
  ifstream inDictFile(PathName,ios::in)


Any ideas wht I'm getting ifstream as ambiguous? Does it have anything to do with the includes for iostream.h and fstream.h?
Pls help!
  • 2
1 Solution
>> Does it have anything to do with the
>> includes for iostream.h and fstream.h?
Yes.  Those are older "new" include files.  Switch to the versions without the .h files <iostream> and <fstream> and the problem will go away.

One difference will be that the include files you used try to place their contents in the global namespace and the proper include files (the ones I suggested) place them in the "std" namespace.  (The ones you were using, use the ones I suggest and that is what leads to this problem at times.)  So when you switch to the files I suggested, you will find that all the classes etc are now in the "std" namespace, so you will either have to proceed the names with "std::" like

std::fstream Fil;

or you will have to use a using declaration like

using namespace std;

to tell the compiler to use all the contents of the std namespace.
nicolacAuthor Commented:
Thanks a million. :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now