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

Ambiguous symbol error

Hi,
The following snippet cause a compilation error:

...
using namespace std;

ifstream fin;
...


error C2872: 'ifstream' : ambiguous symbol

How can I solve it?
0
s_lavie
Asked:
s_lavie
  • 5
  • 4
  • 2
  • +1
1 Solution
 
GloriousRainCommented:
try ifstream::ifstream fin;
0
 
s_lavieAuthor Commented:
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
 
nietodCommented:
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
MDarlingCommented:
Did you include the header?

...

#include <fstream>

using namespace std;

ifstream fin;

...


Regards,
mike.
0
 
MDarlingCommented:
Mine is the same comment as nietod (which wasn't there until I pressed submit).

Regards,
Mike.
0
 
s_lavieAuthor Commented:
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
 
nietodCommented:
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
 
nietodCommented:
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
 
s_lavieAuthor Commented:
Thanks nietod, but I would like to see the explaination!
0
 
s_lavieAuthor Commented:
Thanks nietod, but I would like to see the explaination!
0
 
nietodCommented:
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
 
s_lavieAuthor Commented:
Network problems... thanks anyway!
0
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

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

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