< previous page page_137 next page >

Page 137
ch = A ;
you can store the newline character into a variable:
ch = \n ;
You also can put the newline character into a string just as you can any printable character:
cout << Hello\n;
This last statement has exactly the same effect as the statement
cout << Hello << endl ;
But back to our discussion of input. Let's look at some examples using the reading marker and the newline character. In the following table, i is an int variable, ch is a char variable, and x is a float variable. The input statements produce the results shown. The part of the input stream printed in color is what has been extracted by input statements. The reading marker, denoted by the shaded block, indicates the next character waiting to be read. The \n denotes the newline character produced by striking the Return or Enter key.
StatementsContents After InputMarker Position in the Input Stream
1.two.gif 5 A16.9\n
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
cin >> i;
i = 2525sbox.gif A 16.9\n
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
cin >> ch;
ch = A25 Asbox.gif 16.9\n
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
cin >> x;
x = 16.925 A 16.9slashn.gif
2.two.gif 5\n
A\n
16.9\n
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
cin >> i;
i = 2525slashn.gif
A\n
16.9\n
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
cin >> ch;
ch = A25\n
Aslashn.gif
16.9\n

(table continued on next page)

 
< previous page page_137 next page >