qdii
qdii

Reputation: 12963

Errors when iostringstream::write is called

On this website, the description of the iostringstream::write function says that:

In case of error, the badbit flag is set

What could those errors be?

Upvotes: 0

Views: 482

Answers (1)

Jerry Coffin
Jerry Coffin

Reputation: 490108

The obvious error when writing to a stringstream would be if the underlying stringbuffer failed to allocate memory to hold the data being written. Also note, however, that the link you've given is to ostream::write, which could fail for other reasons (e.g., writing to a pipe that's been closed or a file on a disk that's full and/or the write would exceed what the user's allowed).

Aside #1: there's no such thing as an iostringstream -- there's istringstream and ostringstream. The one that combines both is just stringstream.

Aside #2: cplusplus.com isn't particularly highly respected. Some other sites (e.g., cppreference.com) seem to be more dependable/accurate, at least as a general rule (though I feel obliged to point out that I don't use any of the above much myself, so my comments on them aren't anywhere close to the last word).

Upvotes: 3

Related Questions