What is the maximum std :: ostringstream buffer size?

Is the size allocated based on the amount of dynamically allocated memory? what happens when we reach this limit, is there an exception or is it overwritten in some other part of the memory? Or does he silently stop writing to the buffer?

+3
source share
2 answers

Just as std::coutif the stream is down (for some reason), the buffer state (eofbit, failbit or badbit) will be set. This will mean that operator bool()for the stream will be evaluated to false.

std::ostringstream oss;
// a lot of output to oss here - causing a situation where you are out of available memory
if (!(oss << some_value))
{
    // oss failed to write some_value!
}

Note. Prior to C ++ 11, this was accomplished with operator void*().

, , ( ), , std::ios::exceptions().

+2

std::stringstream std::string. , std::string::max_size(). , , . std::ios_base::badit . , , , .

+2

All Articles