- Jul 6, 2005
- 9
- 0
- 0
So I am taking in an int from the console in stream and when I type in a string instead, my program goes into an infinite loop. How can I handle this error in code?
(code example would look something like this)
{
int myInt = 0;
cout<<"Enter in an int here."<<endl;
cin>>myInt; //if input here is "aStringNotInt" then my program crashes.
}
(code example would look something like this)
{
int myInt = 0;
cout<<"Enter in an int here."<<endl;
cin>>myInt; //if input here is "aStringNotInt" then my program crashes.
}