|
|
Output |
|
printf isn't used very much C++. Instead cout
and the << operator are typically used.
cout is a global variable defined in iostream
that is the output object tied to standard output (normally the
terminal).
Formatting the output as with printf is difficult (you
have to use manipulators) so we're not going to be concerned with
specific formatting in this class.
The general format is
cout << <var1> << <var2> <<
<var3>;
endl is a special identifier that puts a \n
character into the string and forces the flushing of the buffer.
In the following example the even numbers 2 through 18 are printed.
#include <iostream>
using namespace std;
int main (int argc, char** argv) {
cout << "Here are the even numbers\n";
for (int i = 0; i < 10; i++) {
int j = 2 * i;
cout << j << "\n";
}
cout << endl;
return 0;
}