Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Ambiguous symbol error

Posted on 2001-07-03
12
Medium Priority
?
599 Views
Last Modified: 2007-11-27
Hi,
The following snippet cause a compilation error:

...
using namespace std;

ifstream fin;
...


error C2872: 'ifstream' : ambiguous symbol

How can I solve it?
0
Comment
Question by:s_lavie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 2

Expert Comment

by:GloriousRain
ID: 6248093
try ifstream::ifstream fin;
0
 
LVL 2

Author Comment

by:s_lavie
ID: 6248143
I did and I got:
error C2146: syntax error : missing ';' before identifier 'fin'
error C2277: 'ifstream::ifstream' : cannot take address of this member function
0
 
LVL 22

Expert Comment

by:nietod
ID: 6248181
We probably need to see more code, but did you remember to include <fstream>, the include file that defines the ifstream class--and lots of other file stream classes?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:MDarling
ID: 6248183
Did you include the header?

...

#include <fstream>

using namespace std;

ifstream fin;

...


Regards,
mike.
0
 
LVL 3

Expert Comment

by:MDarling
ID: 6248187
Mine is the same comment as nietod (which wasn't there until I pressed submit).

Regards,
Mike.
0
 
LVL 2

Author Comment

by:s_lavie
ID: 6248224
Here is the code:

#include <fstream.h>
#include <vector>

using namespace std;

int main()
{
     ifstream fin; // the line that causes the above-mentioned error

     return 0;
}

Note: #include <vector> is a must, since I use it later...
0
 
LVL 22

Accepted Solution

by:
nietod earned 200 total points
ID: 6248257
The problem is that you are using the wrong header.  Replace <fstream.h> with <fstream>

I have an explaination that I have to find.
0
 
LVL 22

Expert Comment

by:nietod
ID: 6248272
The official STL (Standard Template Library) files are all extensionless files, like <iostream>, <vector>, and <list>.  You may find that your compiler has files with these names but a .h extension, like <iostream.h>, <vector.h>, and <list.h> but these are not the standard files.  These files are old, non-standard files that are provided for compativbility for old programs that used them before the standard files were settled upon.  You want to avoid usign this files if you have the standard ones availalbe.  The non-stnadard files may not have all the features of the standard ones, they also likely to have more bugs and other problems, and also since they are not standardized, they will varry from compiler to compiler, and might not even exist on many compilers.  So avoid using these files if you have the extenionless, standardized files.

Now there is one big difference between the standardized files and many of the non-standardized files.  The standardized files place all of their symbolic names in the "std" namespaces.  This is so that the names defined in these files don't clash with names you write in your program.  So in order to access the names inside the standard STL files you need to prefix them with "std::" like

std::vector<std::string> StringArray;

If you do not wish to use those "std::",  you can instead add a using directive like

using namespace std;

after you include the STL  include files.  Then these names will all be brought into your namespace.
0
 
LVL 2

Author Comment

by:s_lavie
ID: 6248275
Thanks nietod, but I would like to see the explaination!
0
 
LVL 2

Author Comment

by:s_lavie
ID: 6248286
Thanks nietod, but I would like to see the explaination!
0
 
LVL 22

Expert Comment

by:nietod
ID: 6248308
Well you got it.  Proposed as an answer on a question with an accepted answer?   Try not to think about that it causes headaches.
0
 
LVL 2

Author Comment

by:s_lavie
ID: 6248374
Network problems... thanks anyway!
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

722 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