Beside the built-in types, the C++ compiler is often accompanied with lot of files containing predefined types. The main one we will use in our example programs is the stream type.

To use it, we need to indicate to the compiler to include in our source file another file called iostream (where this class type is defined).

#include <iostream>
int main(int argc, char **argv) {
int k;
k = 14;

k = k + 4;
k = k * 2;
cout << k << ‘\n’;
}

The variable cout is defined in the included file and is of type ostream. The only thing we need to know for now is that we can display a variable of a built-in type by using the << operator.
We can also read values with cin and the >> operator.
 The following program gets two float values from the user and prints the ratio.

#include <iostream>
int main(int argc, char **argv) {
double x, y;
cin >> x >> y;
cout << x / y << ’\n’;
}

Note that with recent versions of the GNU C++ compiler, you have to add
using namespace std; after the #include.

Designed By Blogger Templates | Templatelib & Distributed By Blogspot Templates