Deriving streambuf or basic_ostringstream?

Posted by Helltone on Stack Overflow See other posts from Stack Overflow or by Helltone
Published on 2010-03-17T07:42:10Z Indexed on 2010/03/17 7:51 UTC
Read the original article Hit count: 315

Filed under:
|
|
|

Hi, I want to derive a stringstream so that I can use the operator<< to construct a message which will then be thrown. The API would look like:

error("some text") << " more text " << 42 << std::endl;

This should do a

throw "some text more text 42"

So what I did is make an errorbuf (inheriting from streambuf) which overloads the 'overflow' method and then create an ostream(&errorbuf). I wonder if I shouldn't instead inherit from basic_ostringstream or something...

© Stack Overflow or respective owner

Related posts about c++

Related posts about ostream