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

6th Oct 2017, 11:41 PM
K1llJ0Y
K1llJ0Y - avatar
2 odpowiedzi
+ 2
Change line 24: cin >> str; to: getline(cin, str);
7th Oct 2017, 3:09 AM
ChaoticDawg
ChaoticDawg - avatar
+ 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/
6th Oct 2017, 11:54 PM
John Wells
John Wells - avatar