Text I/O and Text Files
Let’s re-examine the concept of text I/O. When you use cin for input, the program views input as a series of bytes, with each byte being interpreted as a character code. No matter what the destination data type, the input begins as character data—that is, text data. The cin object then has the responsibility of translating text to other types. To see how this works, let’s examine how different code handles the same line of input.
Suppose you have the following sample line of input:
38.5 19.2
Let’s see how this line of input is handled by cin when used with different data types. First, let’s try type char:
char ch;cin >> ch;
The first character in the input line is assigned to ch. In this case, the first character is the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access