Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Easy File I/O question 1

Status
Not open for further replies.

Vovin

Programmer
Aug 24, 2003
63
GB
Hi,

this is probably really easy but I don't know how to do it. I have a piece of code that opens a file and reads it's contents. The first time I open the file this code works fine - the second time it doesn't. I have checked all my opens and they all have matching close's.

My question is this. How do I get more information on why the file failed to open? Any help would be very much appreciated.

Here is some of my code if that's any help:
ifstream iniFileStream(REASONS_INI_FILE_NAME.c_str());
if (iniFileStream.is_open())
{
sprintf(log_msg, "SignDocInterface.cpp: opened reasons.ini file \n");
log();

char buffer[255];
for(index = 1; !iniFileStream.eof(); index++)
{
iniFileStream.getline(buffer, sizeof(buffer));
entryRef = sADMList->InsertEntry (listRef, index);
sADMEntry->SetText (entryRef, buffer);
sADMEntry->Select (entryRef, true);
}

}
else
{
// TODO: 2nd time we open dialog we get this message - Why???????????
sprintf(log_msg, "SignDocInterface.cpp: Failed to open reasons.ini file \n");
log();
}
sprintf(log_msg, "SignDocInterface.cpp: Closing reasons.ini file \n");
log();
iniFileStream.close();
 
the best way is by using GetLastError()
or in the console i think its something todo with err?

With GetLastError you can format the error as a string (FormatMessage IIRC) then display as you please.


Skute

"There are 10 types of people in this World, those that understand binary, and those that don't!"
 
Thanks Skute,

I managed to get to the root of the problem. For some reason the current working directory was getting changed.

It's good to know about GetLastError() though. I'll maybe give it a go as I'm running across a few of these types of problems.

Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top