Cin error bit

T

tdog

I am reading in io input using 'cin' in a do-while loop. But the
error bit apparenlty keeps getting set, leaving the console in a
"frozen" state until I hit enter twice.
How do I reset this error bit?
Thanks.
 
B

brekehan

I am reading in io input using 'cin' in a do-while loop. But the
error bit apparenlty keeps getting set, leaving the console in a
"frozen" state until I hit enter twice.
How do I reset this error bit?
Thanks.

Don't forget to put in some example code in order to get a good
answer. These fellers are picky about that :)
 
T

tdog

Sample code (that errors):

bool bNotValidInput = false;
string sInputData;

do
{
cin.clear();
cin >> sInputData;

//freezes here

if( ...Some-Data-Check...)
{
bNotValidInput = true;
}
else
{
bNotValidInput = false;
} //if

} while (bNotValidInput);
 
B

BobR

tdog said:
Sample code (that errors):

PLEASE, do not top-post.
bool bNotValidInput = false;
// > string sInputData;

std::string sInputData;
// > cin.clear();
// > cin >> sInputData;
std::cin >> sInputData;
file://freezes here

if( ...Some-Data-Check...){
bNotValidInput = true;
}
else{
bNotValidInput = false;
} // if

std::cin.clear();
// try this:
// #include <limits>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,201
Messages
2,571,052
Members
47,656
Latest member
rickwatson

Latest Threads

Top