0

请考虑以下代码:

std::stringstream test;
test << std::string("This is a test.");
std::string str;
test >> str;
std::cout << "\"" << str << "\"" << std::endl;

这仅输出字符串“This”,而不是“This is a test”。

为什么会这样,我怎样才能得到整个字符串?

4

1 回答 1

5

std::stringstream::str

std::string str = test.str();
于 2013-03-11T23:50:04.023 回答