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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
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’sistringstreamandostringstream. The one that combines both is juststringstream.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).