0
Reversing strings, works with one word. But when two words the second word is cut off
I'm doing this for coderbyte, I'm using a function called reverseStr to take a string entered by the user, reverses it, and spits it back. this works perfectly if one word I entered, however if more are entered, only the first word is used and the rest is cut off, for example inputting "word" returns "drow", and entering "two words" returns "owt" https://code.sololearn.com/cyICNV35G88J/?ref=app
2 ответов
+ 2
Change line 24:
cin >> str;
to:
getline(cin, str);
+ 2
Your cin is only reading the first string in as whitespace stops it. There is a section "cin and strings" giving more information.
http://www.cplusplus.com/doc/tutorial/basic_io/