How can I input a string into my programme with getline function? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can I input a string into my programme with getline function?

8th Aug 2019, 11:05 AM
János Gorondi
János Gorondi - avatar
6 Answers
+ 7
Shadow "For Sololearn,somehow std::getline() doesn't trigger the input console" May I please know what did you mean by that. I have used this getline function atleast in 2-3 of my codes on sl and input wizard appears as usual so I'm bit confused what did you mean. Thank you.
8th Aug 2019, 12:22 PM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 7
Shadow your provided code doesn't prompt window due to spaces in parameters.//weakness of SL IDE edit: https://code.sololearn.com/cs4299LPYLuC/?ref=app
8th Aug 2019, 12:43 PM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 6
http://www.cplusplus.com/reference/string/string/getline/ https://en.cppreference.com/w/cpp/string/basic_string/getline
8th Aug 2019, 11:34 AM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 4
Define a string and then store the input there, e.g. std::string userInput; std::getline( std::cin, userInput ); Reference: http://www.cplusplus.com/reference/string/string/getline/ For SoloLearn, somehow std::getline() doesn't trigger the input console. A workaround would be to place #define dummy std::cin >> somewhere in your program, then everything should work as expected.
8th Aug 2019, 11:37 AM
Shadow
Shadow - avatar
+ 4
🇮🇳Omkar🕉, at least for me the following skips the input wizard: https://code.sololearn.com/cAY0AlCN5Htm/?ref=app
8th Aug 2019, 12:34 PM
Shadow
Shadow - avatar
+ 2
Lol, okay, compile-wise that makes absolutely no sense as whitespaces should be ignored by a compiler, but alright. Ignore my previous statement in that case.
8th Aug 2019, 12:52 PM
Shadow
Shadow - avatar