hat do a command shell, an online ordering system, and a report generator application have in common? Not much, really. Yet they all base their operation on an external source of data, be it a human user or a data file. By their nature, such applications must be prepared to detect invalid input and handle it in a reasonable manner.
The standard <iostream> library offers only a limited input-validation mechanism. How can you ensure that users don't accidentally enter a string as their zip code, for example? Although cin can detect such anomalous conditions, it has a cumbersome interface that doesn't provide sufficient information about the cause of the error. Worse yet, cin doesn't recover from errors automatically.
Instead of relying on cin to validate input, read the input as a string and then check it. If the string passes the test, convert it to the desired type, say int or double.