why while(cin>>num) one time

I had a homework to create two stacks from int,and then compare him.
it's good, but if i input like that:

int num;
stack<int> s;
while(cin<<num)
{
s.push(num);

}

second time when i do this to input in another stack,
the program break the input : i can' t input for second stack!!!

But if use stack of char i haven't this problem.
Can someone tell me where is the problem.

PS. to input numbers in two stacks, i can transformate chars into int but it's the hard way i think
it should be cin >> num
If you stop the loop by entering an invalid value, cin would fail and it would stop getting input
http://www.cplusplus.com/forum/articles/6046/
Topic archived. No new replies allowed.