0

例如:

void Display()
{
    cout << "Hello World" << endl;
}

stringstream ss;

如何将display方法输入到ss字符串流中?

4

1 回答 1

3
// Save the old cout's streambuf 
streambuf* old = cout.rdbuf();

ostringstream oss;

// replace cout's streambuf with the ostringstream's
cout.rdbuf(oss.rdbuf());

// Call Display
Display();

// Restore the old cout
cout.rdbuf(old);

评论本身的解释。

于 2013-04-15T17:54:37.637 回答