+ 1
get() funct to get user string input
Why it display error when i run it? I used ‹string> header and cin.get() func... is this wrong?
4 Antworten
+ 5
std::cin.get() is standard.
http://www.cplusplus.com/reference/istream/istream/get/
+ 4
The get method is used to read single characters or a c-string. It does not work for strings. To read a string, use getline with the following syntax:
getline(<input_stream>, <reference_to_string>, [delimiter]);
Eg: string s; getline(std::cin,s);
For more details:
http://www.cplusplus.com/reference/istream/istream/get/
http://www.cplusplus.com/reference/string/string/getline/
+ 2
Thanks Kinshuk.. just wanna ask, is this only for sololearn compiler or valid for all compiler? I think i can use the get() func in a normal destop c++ compiler..
+ 2
This should have the same behaviour on all platforms, as this is how the get method is defined for the istream class under the header istream. There is no overload present for C++ strings, as those came later.
If possible, can you share the code that used get for strings and compiled on your PC?