+ 3
Best way to get strings [solved]
I used to use "getline( cin >> ws, str);" but in references I noticed that they use "getline ( cin, str);" So what's the best way of get this strings
7 Respostas
+ 3
I played with BroFar's code and arrived to this conclusion:
Given " String with withespaces" as input.
getline(cin, str); str is now the given string.
getline (cin >> ws, str); str is now:
"String with withespaces" , notice how the initial withespaces got removed.
+ 4
Elliot Larez if you go to my second code this is actually the way to get rid of all ws thanks to Ipang for flashing a trigger
+ 3
Elliot Larez not sure if this is what you mean but it includes whitespace between words:
? Are you trying to eliminate whitespace ?
https://code.sololearn.com/cE3ul692h6QD/?ref=app
https://code.sololearn.com/c9jQe2mAn0r6/?ref=app
+ 3
Quoted from https://en.cppreference.com/w/cpp/io/manip/ws
std::ws
"Discards leading whitespace from an input stream."
+ 2
Elliot Larez
One usecase of `std::ws` I happen to know, is to read a `std::string` after reading a number using `std::cin` like in this code below 👇
There may be other usecases that I just don't know yet.
https://code.sololearn.com/c67K7qd8MpGO/?ref=app