CristianD
CristianD

Reputation: 138

Stringstream returning blank value

Why does this program print out blank?

  string str;
  stringstream ss(str);
  ss << "A string";

  cout << str; // just blank

Upvotes: 0

Views: 202

Answers (1)

flogram_dev
flogram_dev

Reputation: 42888

stringstream is not going to modify the argument you pass to its constructor.

Instead, you can get the current buffer from the stringstream by calling its str member function:

cout << ss.str();

Next time, consider reading the documentation.

Upvotes: 1

Related Questions