Click to See Complete Forum and Search --> : ambiguous Symbol


goobers
March 15th, 2005, 10:58 AM
Hi,

i Have the following code:

using namespace std;
char str[2000];
string file = "foo.txt";
char* cwd = getcwd(NULL, 0);
string path = cwd;
free(cwd);
(path += "/") += file;
fstream file_op(path.c_str(), ios::in);
file_op.getline(str,1999);
file_op.close();

problem is i am getting an error during compile:

error C2872: 'fstream' : ambiguous symbol


i searched and i found that it might have something to do with headers. These are the headers i used:


#include <windows.h>
#include <fstream.h>
#include <direct.h>
#include <string>

(note that the above is only a portion of the full code)


anyone know what is causing the error? thanks

Leo77
March 15th, 2005, 11:12 AM
try include
#include <fstream>
instead of
#include <fstream.h>

Paul McKenzie
March 15th, 2005, 11:47 AM
i searched and i found that it might have something to do with headers. These are the headers i used:

#include <windows.h>
#include <fstream.h>
Do not mix up non-standard headers with standard headers. Always use the standard headers (the headers with no .h).

Corrections:

#include <fstream> // no .h

Regards,

Paul McKenzie

goobers
March 15th, 2005, 08:52 PM
hi,

that worked.. but now i am getting different errors during linking:


LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/main.exe : fatal error LNK1120: 1 unresolved externals

jawadhashmi
March 15th, 2005, 10:19 PM
would you please write the whole code/program

Ejaz
March 16th, 2005, 12:25 AM
Are you sure that you have a main() in your program?

goobers
March 16th, 2005, 04:40 AM
I included tchar.h and it worked fine.. i wonder why ..