Hi all,
When the following code is executed, we cannot input any string with white-space.
What if I actually want to input several words separated by white-spaces? How should I do that
Thanks in advance:)
Code:string temp;
cin>>temp;
Printable View
Hi all,
When the following code is executed, we cannot input any string with white-space.
What if I actually want to input several words separated by white-spaces? How should I do that
Thanks in advance:)
Code:string temp;
cin>>temp;
Use the version of std::getline for std::string.
Alternatively, you can also use the noskipws manipulator. I'd recommend the getline method though.
How to use the getline?
I tried
Should I include a header file to make that work?Code:string temp;
cin.getline(temp,20);
OK, thanks!
I tried
And it worked.Code:getline(cin,temp)