Archived

This topic is now archived and is closed to further replies.

Allebarde

VC++ error

Recommended Posts

Allebarde    122
Hi! I found a source, and when I try to compile, I get an error: ifstream fin(strSkin); : error C2872: ''ifstream'' : ambiguous symbol I include this .. #include <windows.h> #include <stdio.h> #include <stdlib.h> #include <math.h> #include <string> #include <fstream> #include <vector> #include <crtdbg.h> using namespace std; .. does anyone see the problem?

Share this post


Link to post
Share on other sites
taratr98    122
It might be a namespaces problem. You're using the std namespace, and that fact might be ambiguating your use of ifstream.

There's an ifstream in the std namespace - from <fstream.h> (which might be included in <windows.h> or elsewhere) and there's an ifstream in the ios namespace from <fstream>.

So, you might try declaring it like this:
ios::ifstream fin(strSkin);

which will hopefully make clear to the compiler which version of ifstream you're trying to use.

-ATR-

[edited by - taratr98 on May 6, 2002 11:12:27 AM]

Share this post


Link to post
Share on other sites
Allebarde    122
Shit! Now I get this:

ios::ifstream fin(strSkin);

error C2039: ''ifstream'' : is not a member of ''ios''
c:\program files\microsoft visual studio\vc98\include\ios.h(106) : see declaration of ''ios''
error C2872: ''ifstream'' : ambiguous symbol

Share this post


Link to post
Share on other sites
Oluseyi    2103
quote:
Original post by taratr98
There''s an ifstream in the std namespace - from <fstream.h> (which might be included in or elsewhere) and there''s an ifstream in the ios namespace from <fstream>.

No. There''s an ifstream in the std namespace - from <fstream>, and there''s an ifstream in the global namespace - introduced by including <fstream.h> You shouldn''t be using the old ".h" C++ headers anyway. Use <fstream>.

<windows.h> doesn''t include any non-Win32 headers.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ ]
[ MS RTFM [MSDN] | SGI STL Docs | Boost ]
[ Google! | Asking Smart Questions | Jargon File ]
Thanks to Kylotan for the idea!

Share this post


Link to post
Share on other sites
declspec    126
C++ is compatable with C. meaning C code will compile but not neccesarily the sameway under the hood. infact not usually. ... hrmm im beating around the bush.

basically lots of existing code doesnt use namespaces so youll find two of every... hrmm thats not good either.


check it out dont mix:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

with
#include <string>
#include <fstream>
#include <vector>

whats happening is one is providing ifstream (fstream) and so is another (stdio.h). fstream file puts ifstream in a namespace called std and the stdio file puts it global.

if your going to use namespaces use all the header files without the ".h". see the issue here is that stdio.h comes from C. so C code can use it in C++ as per the goal that C compiles in C++ but all its really doing is wrapping ifstream without a namespace. thats not standard C++ thats just the way they decided to implement the goal. there is no standard in that department. but it makes sense.

ahh but you want the other junk in those libraries?

use:
#include <cstdlib>
#include <cmath>
#include <ctime>

with
#include <istream> etc


those will provide the C functions you know and love but in a namespace/ C++ stl compatible way.

guess the shortversion is you were hacking together the C library and C++ technically and it never bit ya until now. but like i said werent trying to screw you out of your C function knowledge. its just that you got to use the c++ STL versions... the 3 i gave.


damn i can be a windy mug =)

Share this post


Link to post
Share on other sites
Oluseyi    2103
stdio.h doesn''t provide ifstream. And you can use C headers with C++ without repercussions. It''s using old C++ header with the new ones that causes problems. The old C headers were repackaged and placed within the std namespace: cstdio instead of stdio.h, cmath instead of math.h, cstring instead of string.h, cctypes instead of ctypes.h and so on.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ ]
[ MS RTFM [MSDN] | SGI STL Docs | Boost ]
[ Google! | Asking Smart Questions | Jargon File ]
Thanks to Kylotan for the idea!

Share this post


Link to post
Share on other sites