This document furnishes some examples of input and output in C++ Note on Namespaces: If you are using a modern C++ complier you will need to bring the 'cin', 'cout', 'endl' symbols into your namespace by adding a statement like: using namespace std; or (perhaps better, since less inclusive) adding statements like: using std::cin; using std::cout; using std::endl; at the top of the file, after the #include Echoing the input to the output: #include // This needs to be in all the following examples int ch; while (cin >> ch) { cout << ch; } An alternative way of echoing the input to the output: int ch; while ((ch = cin.get()) != EOF) { cout.put(ch); } Two alternatives for inputing a whole line (not just one word): const int SIZE = 80; int ch; char buffer[SIZE}; cin.get(buffer, SIZE); cout << "The string read was: " << buffer << endl; cin >> ch; // get the newline character which is still there ------------------------------------------------------------------- const int SIZE = 80; char buffer[SIZE}; cin.getline(buffer, SIZE); cout << "The string read was: " << buffer << endl; // newline character has been removed automatically by getline() Inputing an integer (with a check that an integer was read): int num; cin >> num; if (cin.good()) { cout << "Read the integer " << num << endl; } else { cerr << "Failed to input an integer" << endl; } An alternative way of inputing an integer (with a check): int num; cin >> num; if (cin.fail()) { cerr << "Failed to input an integer" << endl; } else { cout << "Read the integer " << num << endl; } Controlling the precision of floating point numbers on output: #include double sqrt2 = sqrt(2.0); for (int places = 0; places < 10; places++) { cout.precision(places); cout << sqrt2 << endl; } Controlling the field width of integer numbers on output: int num = 87; for (int places = 0; places < 10; places++) { cout.width(places); cout.fill('*'); // pad with *'s (default is spaces) cout << "field width:" << places << "num:" << num << endl; }