+ 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?

22nd Jun 2020, 10:51 AM
Rushikesh Kate
Rushikesh Kate - avatar
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.
22nd Jun 2020, 11:30 AM
Harsh
Harsh - avatar
+ 1
char s[25]; cin.getline(s,25); OR string s = " "; cin.ignore(); getline(cin, s);
22nd Jun 2020, 11:39 AM
Rushikesh Kate
Rushikesh Kate - avatar