< previous page page_139 next page >

Page 139
the syntax for calling a void function, not a value-returning function. The function call is a complete statement; it is not part of a larger expression.
The effect of the above function call is to input the next character waiting in the streameven if it is a whitespace character like a blankand store it into the variable someChar. The parameter to the get function must be a variable, not a constant or arbitrary expression; we must tell the function where we want it to store the input character.
Using the get function, we now can input all three characters of the input line
R 1
We can use three consecutive calls to the get function
cin.get(ch1);
cin.get(ch2);
cin.get(ch3);
or we can do it this way:
cin >> ch1;
cin.get(ch2);
cin >> ch3;
The first version is probably a bit clearer for someone to read and understand.
Here are some more examples of character input using both the >> operator and the get function. All of ch1, ch2, and ch3 are char variables. As before, \n denotes the newline character.
StatementsContents After InputMarker Position in the Input Stream
1.a.gif B\n
CD/n
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
cin >> ch1;
ch1 = AAsbox.gif B\n
CD\n
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
cin >> ch2;
ch2 = BA Bslashn.gif
CD\n
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
cin >> ch3;
ch3 = CA B\n
Cd.gif \n

(table continued on next page)

 
< previous page page_139 next page >