+ 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