+ 2

Why cin method in cpp dont take spaces as input?

When i declare a string 's' in cpp and then gets input by cin and let user enters : ram 45 cat then cin only get ram not spaces and characters after it?

13th Jun 2020, 5:03 PM
SUNIL MISHRA
SUNIL MISHRA - avatar
4 odpowiedzi
+ 5
If using getline(), make sure you know which one you're using. c++ string in <string> http://www.cplusplus.com/reference/string/string/getline/ c string (char* array) in <iostream> http://www.cplusplus.com/reference/istream/istream/getline/
13th Jun 2020, 6:51 PM
ChaoticDawg
ChaoticDawg - avatar
+ 3
Use: getline(cin,s);
13th Jun 2020, 6:07 PM
Olivia
Olivia - avatar
+ 2
'cin' is the functions which gets input till it reads a space, so to get the characters after space we generally use gets function.
13th Jun 2020, 5:39 PM
rahul kundena
rahul kundena - avatar