I have this loop right now that reads in numbers and prints them in decimal, octal and hexadecimal values:
while(1) { if (cin >> n) cout << internal << setfill(' ') << setw(10) << dec << n << internal << setw(12) << oct << n << internal << setw(9) << hex << uppercase << n << endl; if (cin.fail()) { break; } }
However, if I try to discard input that is not numbers, this will not be read in the input after the letters:
if (cin.fail()) { cin.ignore(); }
How to reset input, but can you read other data later?
Input Example:
23 678 786 abc 7777
Expected Result: dec, oct, hex
23 27 17 678 1246 2A6 786 1422 312 7777 17141 1E61
source share