Hi, I noticed you wish to work in the standard namespace, yet you use cin.getline().
Use getline().
Here is a nice piece of code to validate correct input. You can change the int to anyting like a bool in your case.
Code:
//uses <strstream>
string sInLine;
bool bValid = false;
bool bNonDigit = false;
int nNumber;
while( !bValid ) {
cout << "Enter an integer : ";
getline( cin, sInLine );
bNonDigit = false;
for( size_t i = 0; i < sInLine.size(); ++i ) {
if( !isdigit( sInLine[i] ) )
bNonDigit = true;
}
if( bNonDigit )
cout << "The input contains non digits - Invalid\n";
else {
istrstream InStream( sInLine.c_str() );
InStream>> nNumber;
if( !InStream )
cout << "Your number is invalid\n";
else
bValid = true;
}
}
cout << "You entered " << nNumber << endl;