I'm a total newbie to C++, so don't hit me hard :)
I've been trying to grasp how the following piece of code works, but none of the laws of logic seem to apply here.
int a;
while (cin >> a)
cout << a << "\n";
cout << a << "\n";
What I do is I run the code, enter a value for "a"(let's say a 5), terminate the input stream(I hope that's the right word) with an "|", and the output goes as follows:
5
0
So, I feed the program a value, in the loop this value is still what it should be, but just after the loop it becomes a 0 for no reason I can think of. Thus, I wonder what's going on here.