fstream :: more information about failure

E

elitecodex

Hello everyone.

I have a fstream object that i am using... good() returns false. But I
test for both badbit and failbit in the rdstate() and neither appear to
be there... so something seems to be failing elsewhere.

Its a regular text file and there is some text in it.

My question is how can I determine what happened... why good() is not
good and any kind of error message or error code would be great. Do I
have that available to me? If so, what subject do I research to obtain
this information.

Thanks in advance!
 
V

Victor Bazarov

elitecodex said:
Hello everyone.

I have a fstream object that i am using... good() returns false. But
I test for both badbit and failbit in the rdstate() and neither
appear to be there... so something seems to be failing elsewhere.

Its a regular text file and there is some text in it.

My question is how can I determine what happened... why good() is not
good and any kind of error message or error code would be great. Do
I have that available to me? If so, what subject do I research to
obtain this information.

AFAICT, your problem falls under what's answered in FAQ 5.8.

V
 
E

elitecodex

Victor said:
AFAICT, your problem falls under what's answered in FAQ 5.8.

V

Not sure what AFAICT means... but I did manage to find FAQ 5.8 :)

Here is the fstream object.

http://www.dreamscripts.net/BasicFile.h
http://www.dreamscripts.net/BasicFile.cpp

Here is a fragment of code that Im using...

// ... snipped ... //
CBasicFile* infile = new CBasicFile();
char* temp = new char[128];
temp = (char*) memset( temp, '\0', 128 );

CBasicFileReturnCodes retValue =
infile->OpenFile(configFilename.c_str(), MODE_READ | TYPE_TXT);

string _modes = infile->GetModesString();
if ( retValue == SUCCESS )
{
while ( infile->ReadLine(temp, 128) == SUCCESS )
{
config.push_back(wxString(temp));
temp = (char*)memset(temp, '\0', 128);
}
}
delete [] temp;

// infile->Close(); // <-- not needed.. done in deconstructor
delete infile;
// ... snipped ... //

Basically, retValue is returning ERROR_FILE_NOT_GOOD. The _modes
variable is "Read Text". So Im passing fstream::in. Is there any way
to get more detailed information why good() is returning false?
 
E

elitecodex

elitecodex said:
Not sure what AFAICT means... but I did manage to find FAQ 5.8 :)

Here is the fstream object.
// snipped

Nevermind... I got it. My mode was messed up. Thanks anyway!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top