+ 2
C++ - cin and input with spaces
If I try and input a string, namely "strAny", with cin >> strAny; strAny is truncated when it contains a space. Any way and cin-put a phrase with spaces? I tried enclosing in double and single quotes, but neither.
2 Answers
+ 5
You can use
std::getline( std::cin, strAny );
instead. The method reads input until the newline character (or another delimitation character specified by you) is encountered. More information here:
http://www.cplusplus.com/reference/string/string/getline/?kw=getline
+ 2
So helpful, thank you!