Initially my problem was if I input something like "asdf qwer" it would read "asdf" as input for UserID and "qwer" as input for password. So I am trying to make it so it ignores everything after the space and will only read "asdf". After adding cin.ignore, if I input "asdf qwer" it does what I want but instead of reading "asdf" it reads "qwer". How do I get it to read asdf and ignore everything after the space instead of ignoring everything before the space?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
cout << endl << "Please enter UserID: ";
cin.ignore(200, ' ');
cin >> inUserID;
cout << inUserID << endl; //just to check what it reads the input as
cout << "Please enter Password: ";
cin >> inPassword;
cout << "Please enter PIN: ";
cin >> inPIN;
while (!cin)
{
cin.clear();
cin.ignore(200,'\n');
cout << "Please re-enter correct PIN: ";
cin >> inPIN;
}
cin.ignore(100,'\n'); will only ignore 100 characters till '\n' if user enters more than 100 characters after the space this will fail. Apart from that it should work as well