Jump to content
  • Advertisement

Archived

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

Indy

fstream

This topic is 6350 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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!