【发布时间】:2013-04-07 22:38:48
【问题描述】:
例如:
void Display()
{
cout << "Hello World" << endl;
}
stringstream ss;
如何将display 方法输入到ss 字符串流中?
【问题讨论】:
-
ss
标签: c++ string methods stringstream
例如:
void Display()
{
cout << "Hello World" << endl;
}
stringstream ss;
如何将display 方法输入到ss 字符串流中?
【问题讨论】:
标签: c++ string methods stringstream
// 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);
cmets 本身的解释。
【讨论】: