Dave
Dave

Reputation: 1659

Extracting entire std::string From a std::stringstream

Please consider this code:

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

This outputs only the string "This", rather than "This is a test."

Why is this so, and how can I get the entire string?

Upvotes: 0

Views: 76

Answers (1)

Konrad Rudolph
Konrad Rudolph

Reputation: 546153

std::stringstream::str:

std::string str = test.str();

Upvotes: 5

Related Questions