November 2001
Beginner
1128 pages
29h 12m
English
Look at a couple more examples of statements. The program in Listing 2.3 expands on the preceding example by allowing you to enter a value while the program is running. To do so, it uses cin (pronounced cee-in), the input counterpart to cout. Also, the program shows yet another way to use that master of versatility, the cout object.
// yourcat.cpp -- input and output
#include <iostream>
using namespace std;
int main()
{
int fleas;
cout << "How many fleas does your cat have?\n";
cin >> fleas; // C++ input
// next line concatenates output
cout << "Well, that's " << fleas << " fleas too many!\n";
return 0;
}
|
Here is a sample output:
How many fleas does your cat have?
112 Well, that's 112 fleas too ...Read now
Unlock full access