I am a begginner in C++ and in programming generally. I am reading http://www.cprogramming.com/tutorial/lesson1.html this tutorial and I have one question.
Code:
#include <iostream>
using namespace std;
int main()
{
int thisisanumber;
cout<<"Please enter a number: ";
cin>> thisisanumber;
cin.ignore();
cout<<"You entered: "<< thisisanumber <<"\n";
cin.get();
}
I could not understand the purpose of the cin.ignore() function. I recompile the module without the cin.ignore() function and the result was the same.
While running the program, I typed a character instead of a number and the result was the number 2. eg. I typed "s" and the output was "2". I typed 43243432767436482 and the output was 2 again. So what the cin.ignore() really does ?