F-J-K
asked on
How Can I Check Overflows? - I used cin.getline() - C++
Both examples doesn't work. User is expected to insert chars less than MAX_DATA length, but i want to handle the situation when user inserts over MAX_DATA. I tried several examples, non of them worked...
char userInput[MAX_DATA];
cin.getline(userInput, MAX_DATA);
if(cin.failbit)
{
cout<<"Overflow occured. Restart Application"<<endl;
system("pause");
exit(-1);
}
//***************************************************************//
cin.getline(userInput, MAX_DATA);
if(strlen(userInput) > MAX_DATA)
{
cout<<"Overflow occured. Restart Application"<<endl;
system("pause");
exit(-1);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER