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

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();
 
Off the top of my head, you may have to use your ios functions to ensure that the file is at the beginning when you open it.
Code:
 ifstream iniFileStream(REASONS_INI_FILE_NAME.c_str(), std::ios::beg);

James P. Cottingham

There's no place like 127.0.0.1.
There's no place like 127.0.0.1.
 
Thanks for your help. I've managed to get it working though. The problem was that the current working directory was being changed somewhere else in the app.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top