473,386 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

fstream :: more information about failure

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!

Jul 26 '06 #1
4 1329
elitecodex wrote:
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 26 '06 #2
Victor Bazarov wrote:
>
AFAICT, your problem falls under what's answered in FAQ 5.8.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
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?

Jul 26 '06 #3

elitecodex wrote:
Victor Bazarov wrote:

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

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

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!

Jul 26 '06 #4
elitecodex wrote:
Victor Bazarov wrote:
>>
AFAICT, your problem falls under what's answered in FAQ 5.8.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

Not sure what AFAICT means... but I did manage to find FAQ 5.8 :)
What is it, your first day on the 'net? GIYF!

http://www.google.com/search?as_q=afaict

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 26 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Newsgroup - Ann | last post by:
The fstream is supposed to be a replacement of the stdio.h and the exception is supposed to be a replacement of the return error code. So how do I replace my old codes of the style: if (output =...
1
by: Rob Kreger | last post by:
This code works on Windows XP with VC7.1 stl(sxl 3.08 from dinkumware.) #include "stdafx.h" #include <iostream> #include <stdio.h> #include <io.h> #include <fstream> #include <sys/locking.h>
14
by: Mike - EMAIL IGNORED | last post by:
Using RH9, from this fragment: fstream theStream_; string fPath = "myFile"; int mode = O_EXCL | O_CREAT; theStream_.open(fPath.c_str(),mode); I get the failure shown below. ...
0
by: Ramsey | last post by:
I have a unmanaged lib file that creates an fstream object. This lib file is used by a managed dll. Unfortunately when I run the code it crashes when I create the fstream object. I have a...
7
by: DaVinci | last post by:
//error happen even when there existe a a.txt file #include<fstream> #include <string> #include <iostream> using std::string; using std::fstream; int main() { string s = "a.txt"; fstream...
9
by: Someonekicked | last post by:
In my program, I need to open multiple files, and I wont know till after the program execution how many of them (user will enter that value). So I am using a vector of fstream. I am using fstream...
3
by: Belebele | last post by:
The code below does not cause an assertion failure. fstream f; f.open("myfile"); assert( f.is_open() ); However, the one below does fail the assert:
3
by: shyam | last post by:
Hi All I want to know if there is any problem with using fstream.getLine(char*, int ) function. My problem is that when I read a file using it, the program aborts when it reads the...
16
by: HypeBeast McStreetwear | last post by:
Hey Guys I have to make a program where it accepts/denies applications into a club. The program should read in information about applicants (None was given so I believe I have to make up some...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.