+ 1
How can I input a string into my programme with getline function?
6 Antworten
+ 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.
+ 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
+ 6
http://www.cplusplus.com/reference/string/string/getline/
https://en.cppreference.com/w/cpp/string/basic_string/getline
+ 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.
+ 4
🇮🇳Omkar🕉, at least for me the following skips the input wizard:
https://code.sololearn.com/cAY0AlCN5Htm/?ref=app
+ 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.