Jump to content
  • Advertisement

Archived

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

Indy

fstream

This topic is 6268 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

Hi, If I use the fstream i/o lib, how do I scan for file errors? In particular when a file does not exist. I have looked everywhere in the MS VC++ help and cannot find a method. fstream f,mat; f.open("list.txt",ios::in); //MessageBox(hdwnd,result,"",MB_OK); if(ios::fail!=0)MessageBox(hdwnd,"W","e",MB_OK); while (!f.eof()) { f.getline(part[x],15,''\t''); f.getline(description[x],50,''\n''); x++; } ListLoad=true; f.close(); My code is as above. Thanks Indy

Share this post


Link to post
Share on other sites
Advertisement
Isn''t that it right there? Won''t the condition ios::fail != 0 fail if the file doesn''t exist?

Anyway, won''t this do the trick?

  
fstream f, mat;

f.open("list.txt", ios::in);
if(f.is_open())
{
while(!f.eof())
{
f.getline(part[x], 15, ''\t'');
f.getline(description[x], 50, ''\n'');
++x; // gee, I hope x is initialized somewhere =)

}

ListLoad = true;
f.close();
}
else
MessageBox(hwnd, "Load failed", "", MB_OK | MB_ICONEXCLAMATION);

Share this post


Link to post
Share on other sites
fstream will equal NULL if the file was not opened

if tFile was an fstream, then you would put

if(!tFile)

to test if it opened

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!