|
|
|
|
|
|
|
(This statement uses even stranger syntax in the form of the double colon, whose purpose we won't attempt to discuss here.) Later in the chapter, we discuss the meaning behind dot notation. |
|
|
|
| |
|
|
|
|
More About Functions and Parameters |
|
|
|
| |
|
|
|
|
When your main function tells the computer to go off and follow the instructions in another function, SomeFunc, the main function is calling SomeFunc. In the call to SomeFunc, the parameters in the parameter list are passedto the function. When SomeFunc finishes, the computer returnsto the main function. |
|
|
|
| |
|
|
|
|
With some functions you have seen, like sqrt and abs, you can pass constants, variables, and arbitrary expressions to the function. The get function for reading character data, however, accepts only a variable as a parameter. The get function stores a value into its parameter when it returns, and only variables can have values stored into them while a program is running. Even though get is called as a void functionnot a value-returning functionit returns or passes back a value through its parameter list. The point to remember is that you can use parameters both to send data into a function and to get results back out. |
|
|
|
|
|
|
|
|
|
Skipping Characters with the ignore Function |
|
|
|
|
|
|
|
|
Most of us have a specialized tool lying in a kitchen drawer or in a toolbox. It gathers dust and cobwebs because we almost never use it. But when we suddenly need it, we're glad we have it. |
|
|
|
|
|
|
|
|
The ignore function associated with the istream type is like this specialized tool. You rarely have occasion to use ignore; but when you need it, you're glad it's available. |
|
|
|
|
|
|
|
|
The ignore function is used to skip (read and discard) characters in the input stream. It is a function with two parameters, called like this: |
|
|
|
|
|
|
|
|
The first parameter is an int expression; the second, a char value. This particular function call tells the computer to skip the next 200 input characters or to skip characters until a newline character is read, whichever comes first. |
|
|
|
|
|