C++ TUTORIALS - C++ Basic Input/Output
C++ Basic Input/Output
ADVERTISEMENTS
I/O Library Header Files:
Header File | Function and Description |
---|---|
<iostream> | This file defines the cin, cout, cerr and clog objects, which correspond to the standard input stream, the standard output stream, the un-buffered standard error stream and the buffered standard error stream, respectively. |
<iomanip> | This file declares services useful for performing formatted I/O with so-called parameterized stream manipulators, such as setw and setprecision. |
<fstream> | This file declares services for user-controlled file processing. We will discuss about it in detail in File and Stream related chapter. |
ADVERTISEMENTS
The standard output stream (cout):
#include <iostream> using namespace std; int main( ) { char str[] = "Hello C++"; cout << "Value of str is : " << str << endl; }ADVERTISEMENTSThe standard input stream (cin):
#include <iostream> using namespace std; int main( ) { char name[50]; cout << "Please enter your name: "; cin >> name; cout << "Your name is: " << name << endl; }
cin >> name >> age;The standard error stream (cerr):
#include <iostream> using namespace std; int main( ) { char str[] = "Unable to read...."; cerr << "Error message : " << str << endl; }The standard log stream (clog):
#include <iostream> using namespace std; int main( ) { char str[] = "Unable to read...."; clog << "Error message : " << str << endl; }