< previous page page_142 next page >

Page 142
Here are some examples that use a char variable ch and three int variables, i, j, and k:
StatementsContents After
Input
Marker Position in
the Input Stream
1.957 34sbox.gif 1235\n
128 96\n
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
cin >> i >> j;
i = 957, j = 34957sbox.gif 1235\n
128 96\n
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
cin.ignore(100,  \n);
957 34  1235\n
one.gif 28 96\n
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
cin >> k;
k = 128957 34  1235\n
128sbox.gif 96\n
2.a.gif 22 B 16 C 19\n
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
cin >> ch;
ch = AAsbox.gif 22 B 16 C 19\n
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
cin.ignore(100, B);
A 22 Bsbox.gif 16 C 19\n
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
cin >> i;
i = 16A 22 B 16sbox.gif C 19\n
3.a.gif BCDEF\n
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
cin.ignore(2, \n);
ABc.gif DEF\n
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
cin >> ch;
ch = CABCd.gif EF\n

Example (1) shows the most common use of the ignore function, which is to skip the rest of the data on the current input line. Example (2) demonstrates the use of a character other than \n as the second parameter. We skip over all input characters until a B has been found, then read the next input number into i. In both (1) and (2), we are focusing on the second parameter to the ignore function, and we arbitrarily choose any large number like 100 for the first parameter. In (3), we change our focus and concentrate on the first parameter. Our intention is to skip the next two input characters on the current line.
Interactive Input/Output
Remember in Chapter 1 that we defined an interactive program as one in which the user communicates directly with the computer. Many of the programs that you write will be interactive. There is a certain etiquette in-

 
< previous page page_142 next page >