-1

The rest of the program still runs, but none of the cin's prompt the user for input.

double sales;
cout << "(Commision Employee) Please enter the employee's Sales: ";
while (cin >> sales) {
try
{
    employee1.setGrossSales(sales);
}
catch (invalid_argument& e)
{
    cout << "\nException: " << e.what() << "\n\n";
}
cout << "Please re-enter value if an error occured, otherwise enter end-of-file (ctrl+z): ";
}

string ssn;
cout << "(Base Plus Commision Employee) Please enter the SSN with dashes: ";
cin >> ssn;
employee2.setSocialSecurityNumber(ssn);

The cin following the loop doesn't function like I expected it too. What I gather is that cin has a boolean end-of-file marker that is switched to true upon receiving the end-of-file (ctrl+z on windows). It's this marker that prevents cin from operating again. I have found that I can use std::cin.clear(); to clear this marker.

I found this answer here which does a better job at both describing the same issue I had and answering it: while (cin >> x) and end-of-file issues

For my purposes, this was all I needed.

poptonite
  • 11
  • 1
  • 1

1 Answers1

1

ctrl+z is actually 0x1A byte that sets the std::basic_ios::eof to true, which means that associated stream has reached end-of-file.

Windows system can not read beyond the 0x1A (EOF) character but Unix can.

Abhishek Keshri
  • 3,074
  • 14
  • 31