using stringstream
String S = "I am a good boy"
i want to print:
I
am
a
good
boy
My code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
string s, s1;
cin >> s;
stringstream ss;
ss << s;
while (ss >> s1) {
cout << s1 << endl;
}
return 0;
}
|
I am not getting desired output. Please tell me what's wrong in it and how can i fix this?
Line 9 should be: std::getline(cin, s);
This way you get the whole string
okay. got it. Thanks :)
Topic archived. No new replies allowed.