Redirecting stderr to stdout using string stream

I have a code like this

int main()
{
    std::stringstream oss;
    std::cerr.rdbuf( oss.rdbuf() );

    std::cerr << "this goes to cerr";
    std::cout << "[" << oss.str() << "]";
}

But i get the output of the program as

[this goes to cerr]Segmentation fault

How does the program segfault?

5
задан cpx 24 May 2011 в 09:36
поделиться