< previous page page_68 next page >

Page 68
C++ allows the use of ++ and -- in the middle of a larger expression:
alpha = num++ * 3;
In this case, the postfix form of ++ gives a different result from the prefix form. In Chapter 10, we explain the ++ and -- operators in detail. In the meantime, you should use them only to increment or decrement a variable as a separate, stand-alone statement:
0068-02.gif
Output
Have you ever asked someone, Do you know what time it is? only to have the person smile smugly, say, Yes, I do, and walk away? This is like the situation that currently exists between you and the computer. You now know enough C++ syntax to tell the computer to perform simple calculations, but the computer won't give you the answers until you tell it to write them out.
In C++ we write out the results of calculations by using a special variable named cout (pronounced see-out) along with the insertion operator(<):
cout < Hello;
This statement displays the characters Hello on the standard output device, usually the video display screen.
The variable cout is predefined in C++ systems to denote an output stream. You can think of an output stream as an endless sequence of characters going to an output device. In the case of cout, the output stream goes to the standard output device.
The insertion operator < (often pronounced as put to) takes two operands. Its left-hand operand is a stream expression (in the simplest case, just a stream variable such as cout). Its right-hand operand is either an expression of simple type or a string:
cout < The answer is ;
cout < 3 * num;
The insertion operator converts its right-hand operand to a sequence of characters and inserts them into (or, more precisely, appends them to) the output stream. Notice how the < points in the direction the data are going

 
< previous page page_68 next page >