I'm learning C++ from a site and I've studied until this unit : http://ift.tt/2gIYgJe .
I understand this example but I can't understand how .ignore() works ( I don't even understand if it's a proper function or what )
int main()
{
std::cout << "Pick 1 or 2: ";
int choice;
std::cin >> choice;
std::cin.ignore(32767, '\n'); // ignore up to 32767 characters until a \n is removed
std::cout << "Now enter your name: ";
std::string name;
std::getline(std::cin, name);
std::cout << "Hello, " << name << ", you picked " << choice << '\n';
return 0;
}
I tried replacing .ignore(32767, '\n')
with .ignore(1, '\n')
and .ignore()
and it worked just fine aswell . Please enlighten me !
Aucun commentaire:
Enregistrer un commentaire