Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8439031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:53:33+00:00 2026-06-10T07:53:33+00:00

In C++, each stream has a bad bit: This flag is set by operations

  • 0

In C++, each stream has a bad bit:

This flag is set by operations performed on the stream when an error occurs while read or writing data, generally causing the loss of integrity of the stream.

Source

What would cause a stream to “lose integrity” and enter the bad state? This is not the same as the fail state, which most often occurs when an input stream attempts to store a value into a variable that cannot accept said value (such as attempting to store a string into an integer variable).

Note that this question is a more general form of c++ file bad bit, which is specific to file input streams; this question is not an exact duplicate as it applies to both input and output streams in general.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T07:53:35+00:00Added an answer on June 10, 2026 at 7:53 am

    According to cppreference.com :

    The standard library sets badbit in the following situations:

    • Insertion into the output stream by put() or write() fails for any
      reason.

    • Insertion into the output stream by operator<<, std::put_money or
      std::put_time, could not complete because the end of the output
      stream was reached (The facet’s formatting output function such as
      num_put::put() or money_put::put(), returns an iterator iter such
      that iter.failed()==true)

    • Stream is constructed with a null pointer for rdbuf(), or
      putback()/unget() is called on a stream with a null rdbuf(), or a
      null pointer passed to operator<<(basic_streambuf*)

    • rdbuf()->sputbackc() or rdbuf()->sungetc() return traits::eof() to
      putback() orunget()`

    • rdbuf()->pubsync() returns -1 to sync(), to flush(), or to the
      destructor of ostream::sentry on a unitbuf stream

    • Exception is thrown during an I/O operation by any member function of
      the associated stream buffer (e.g. sbumpc(), xsputn(), sgetc(),
      overflow(), etc)

    • Exception is thrown in iword() or pword() (e.g. std::bad_alloc)


    This may be one more reason to choose cppreference.com over http://www.cpluplus.com, see:
    What’s wrong with cplusplus.com?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I write 'one bit' into a file stream or file structure each
I have a text stream which has n lines and each line is one
I have a binary stream that has a very high error rate. The error
Suppose there are ~10,000's of keys, where each key corresponds to a stream of
Each of my 10-15 pages has 100-200 lines of js inside $(document).ready() Would it
Each key in dictionary has list of MANY integers. I need to iterate through
Each user object in my database has an incremental ID (1, 2, 3, ...).
; defining stream-for-each (define (stream-for-each proc s) (if (stream-null? s) 'done (begin (proc (stream-car
I have a table named users and each row (user) has an image. The
i want to read\write a binary file which has the following structure: The file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.