• Advertisement

Archived

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

bad() work in borland right?

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

For some reason, when I compile (in Borland C++ 5.0) and run this, if there is a file named SETTINGS.INI or not, it thinks there is. Anyone see if im doing anthing wrong, or is it a Borland thing?
void checkSettings()
{
ifstream settings("SETTINGS.INI", ios::nocreate);
   if(settings.bad()) 
      makeSettings()
   }
settings.close();
openSettings();
}

void makeSettings()
{
ofstream settings("SETTINGS.INI");
settings << "Line1\r\nLine2\r\n";
settings.close()
}

void openSettings()
{
char[256] Line1;
char[256] Line2;
ifstream settings("SETTINGS.INI", ios::nocreate);
settings >> Line1 >> Line2;
settings.close();
}
 

Share this post


Link to post
Share on other sites
Advertisement
I always used:

if (!file)

rather than

if (file.bad())

and that seems to work for me. But, I haven''t checked the iostream specifications recently and don''t know if that''s technically correct. Perhaps ''bad'' is the flag that indicates something is broken, and you need the ''fail'' flag instead?

Share this post


Link to post
Share on other sites

  • Advertisement