Jump to content
  • Advertisement

Archived

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

nitzan

ifstream and stl

This topic is 5737 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How do I use ifstream and stl together ? To use stl I have to declare "using namespace std", but then fstream.h gets screwed and my ifstream becomes an ambiuous symbol. Any ideas ? Thanks, Nitzan ------------------------- www.geocities.com/nitzanw www.scorchedearth3d.net -------------------------

Share this post


Link to post
Share on other sites
Advertisement
My bad, I figured it out. fstream.h was screwing up because the std:: calls were no longer valid.

So I add std:: to all my stl calls and now it compiles and runs great.

My new question is:

Is the following code (taken from a site explaining STL) valid ?

quote:

vector vec1;
string line;
vec1.clear();
ifstream infile ("stl2in.txt");
while (getline(infile,line,''\n''))
{
vec1.push_back (line);
}



Seems to me it should be :

quote:

std::vector vec1;
std::string line;
vec1.clear();
ifstream infile ("stl2in.txt");
while (getline(infile,line,''\n''))
{
vec1.push_back (line);
}



Nitzan

-------------------------
www.geocities.com/nitzanw
www.scorchedearth3d.net
-------------------------

Share this post


Link to post
Share on other sites
Looks to me like the difference between those snippets is that the first one makes use of including the entire std namespace (though it isn''t shown.)

Saying:

using namespace std;
vector myVector;

Is valid. The vector class is in the namespace std. Without telling the compiler to use the namespace std by default, to declare a vector you would have to say:

std::vector myVector;


aut viam inveniam aut faciam

MoonStar Projects

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!