I'm not sure how std::cin
actually takes inputs from the stream.
For example, my code:
#include <iostream>
int main()
{
std::cout<<"Pick 1 or 2: ";
int choice;
std::cin>>choice;
//std::cin.ignore(32767,'\n');
std::cout<<"Now enter your name: ";
std::string name;
std::getline(std::cin,name);
std::cout<<"Hello, "<<name<<", you picked "<<choice <<'\n';
return 0;
}
When I comment out the std::cin.ignore, the console prints "Pick 1 or 2: ", I entered 1 and it skips waiting for me to enter my name. Instead, I saw "Hello, , you picked 1 choice".
Actually, does cin even takes the null character in the stream, I wonder?