O'Reilly logo

C++ Primer Plus, Fourth Edition by Stephen Prata

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

More C++ Statements

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.

Listing 2.3. yourcat.cpp
// 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required