consider this code snippet in c++ -
string str;
cin>>str;
If I simply press enter at this stage, the pointer moves to next line but keep waiting for the input even if I intentionally want to input an empty string.
My objective is to read a word. And If I press enter, it should be taken as a empty string.
Use std::getline
:
std::string str;
std::getline(std::cin, str);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With