+ 1
String in cpp
string s ; cin >> s; transform(s.begin(), s.end(), s.begin(), ::tolower); cout << s; input : Hello World output:hello why it only convert hello to lowercase?
2 odpowiedzi
+ 6
cin only reads the first word. To read the entire line, use:
getline(cin, s);
http://www.cplusplus.com/reference/string/string/getline/
Edit: The second one.
+ 1
char s[25];
cin.getline(s,25);
OR
string s = " ";
cin.ignore();
getline(cin, s);