谁能解释为什么下面的代码会产生“you!”而不是“你好!”。
int main() {
std::stringstream ss("hello");
ss << " you!";
cout << ss.str() << endl;
}
最佳答案
openmode 必须设置 ate
。
这就是你要找的:
int main() {
std::stringstream ss("hello", std::ios_base::out | std::ios_base::ate);
ss << " you!";
cout << ss.str() << endl;
}
关于c++ - 为什么string stream operator<<会删除原来的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34758339/