void dr1() {
int num1 = 0, num2 = 0;
char str[100];
while (str[0] != '|') {
cout << "Please enter two numbers (enter \"|\" to terminate): ";
cin >> num1;
cin >> num2;
cin.getline(str, 100);
cout << num1 << num2 << endl;
}
}
If a user inputs a string, shouldn't the variable str
read it from the input buffer?
From what I've learned, you cannot input string characters into an int
type and therefore they are left in the buffer. If they are left in the buffer, shouldn't getline()
read whatever input is left in the buffer?