473,395 Members | 1,404 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,395 software developers and data experts.

confused about ios::failbit

What is the difference between ios::failbit and ios::badbit?
When happen the first and when the second?

I try several circumstances to describe when every flag occurs but only ios::failbit I have.

So, when ios::badbit occurs?
If I have a damaged media what occurs?

Is this patform / compiler depended?

Thanks!
Jul 22 '05 #1
1 8465
<- Chameleon -> wrote:
What is the difference between ios::failbit and ios::badbit?
When happen the first and when the second?

I try several circumstances to describe when every flag occurs but only ios::failbit I have.

So, when ios::badbit occurs?
If I have a damaged media what occurs?

Is this patform / compiler depended?

Thanks!


From Josuttis's "The C++ Standard Library":

The difference between failbit and badbit is basically
that badbit indicates a more fatal error:

* failbit is set if an operation was not processed correctly
but the stream is generally OK. Normally this flag is set
as a result of a format error during reading. For example,
this flag is set if an integer is to be read but the next
character is a letter.

* badbit is set if the stream is somehow corrupted of if data
is lost. For example, this flag is set when positioning
a stream that refers to a file before the beginning of a
file.

failbit is also set in concert with eofbit on the first attempt to read
past the end of the stream.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Jul 22 '05 #2

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

Similar topics

13
by: Bo Peng | last post by:
Dear list, I need to add "disable output" feature to a bunch of objects that output to ostream (or ofstream). The least intrusive way to do this is pass them ofstream("/dev/null") but this makes...
3
by: Mike Austin | last post by:
It's the most annoying thing, and causes hours of frustration. Why can't it be resolved? Regards, Mike Austin Example: #include <iostream> #include <string>
1
by: 77123036 | last post by:
#include <iostream> #include <fstream> using namespace std; int main() { fstream inOut( "copy.out", ios_base::in|ios_base::app ); int cnt=0; char ch; inOut.seekg(0);
103
by: Steven T. Hatton | last post by:
§27.4.2.1.4 Type ios_base::openmode Says this about the std::ios::binary openmode flag: *binary*: perform input and output in binary mode (as opposed to text mode) And that is basically _all_ it...
1
by: SantaClaus | last post by:
Hi all, Im getting an exception in the middle of reading a file and here is my code std::ifstream inf; const int bufSize=1024; char tbuffer; std::string filex = path; // may be C:\test.txt const...
2
by: Paulo da Silva | last post by:
Hi! Please consider the following fragment std::cin.exceptions(std::ios::failbit); .... try { is.getline(p,ILEN); ... } catch (std::ios::failure const &problem)
24
by: john | last post by:
In TC++PL3, in 21.3.3, the following definition of ios_base is provided: class ios_base{ public: // ... typedef implementation_defined2 iostate; static const iostate badbit, // stream is...
11
by: rory | last post by:
I am reading a binary file and I want to search it for a string. The only problem is that failbit gets set after only a few calls to getline() so it never reaches the end of the file where the...
4
by: IanWright | last post by:
I'm having trouble with getline function, in the sense that I keep getting an error, and I'm wondering if anyone can help? The code I'm using is below. What it does is to read a line from one...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.