Well, right now, i am trying to understand the cin.ignore() option. So I created following function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
usingnamespace std;
int main()
{
string name; int age;
cout << "please enter your age:" << endl;
cin >> age; cin.ignore(1);
cout << "please enter your name:" << endl;
getline (cin, name);
cout << "I am " << age << " years old and my name is " << name << endl;
}
That's not suprising at all! cin.ignnore(n) extracts n characters. with it being 1, it only extracts the enter. With 2, it waits for another character to be pressed, before continuing.