Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
string s:
stringstream ss << "Invalid Input";
While(!(ss).fail())
{ ss >> s;
cout << s;
}

Outputs:
Invalid
Input

But I want output:
Invalid Input (in single line separated by space)

What I have tried:

setw(1)
stringstream ss << noskipws << "Invalid Input ";
Posted
Updated 14-Jun-16 10:47am

If you need a line the use getline:
C++
 #include <string>
 #include <iostream>
 #include <sstream>
 using namespace std;

int main()
{
  string s;
  stringstream ss;
  ss << "Invalid Input";

  while (ss.good())
  {
    string line;
    getline(ss, line);
    cout << line;
  }
}
 
Share this answer
 
How about std::cout << ss.str() << "\n";
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900