Character I/O

  1. All data is input and output as character data.

    The software automatically controls how the characters should be interpreted.

    Suppose when the following code is run

    int number;
    cin >> number;

    the user enters 10 and hit "enter". The computer actually reads the character '1', '0' and the return character. Knowing that the data should represent an integer, the software then correctly interprets the data as an integer 10 and assign it to the variable number.

  2. However this kind of high-level automatic conversion can sometimes get in the way. Fortunately C++ has some low-level facilities for handling characters in I/O that allow one to get around this and other I/O problems.