C++ Input and Output
The standard libraries provide a set of input and output capabilities. It is based on the stream concept. The C++ language take place in streams are sequences of bytes.
Bytes flows from main memory to device like a printer, display screen and etc is called Output operation.
Bytes flow from the device like a printer, display screen and etc to main memory is called Input operation.

Input/output Library Header Files:
Header File | Description |
---|---|
It defines the cin, cout, cerr and clog objects which belongs to the standard output stream, standard input stream, and the buffered/un-buffered standard error stream. | |
This header file declare services useful for performing format input/output, such as setw and setprecision. | |
This header file help to declare services for user-controlled file processing. |
cout(Standard Output stream):
- COUT is an instance of the ostream class. It says that “connected to” the output standard device.
- It is used in conjunction with the stream insertion operator. It is written as cout <<. It determines the appropriate stream insertion operator to display the value.
- It is overloaded to output data items of built-in like float, integer, double, pointer and string values. It can be used more than once in a single statement.
Example for cout:
#include <iostream> using namespace std; int main() { cout << "Welcome to Onlinetpoint"; return 0; }
cin(Standard Input stream):
- The predefined object Standard Input stream(cin) is an instance of the istream class.
- The object is said to be the standard input device.
- Used in conjunction with the stream extraction operator.
- It is written as cin >> and may be used more than once in a single statement.
Example for cin:
#include <iostream> using namespace std; int main() { int a,b,c; cout << "Enter the numbers:"; cin >> a >> b; c=a+b; cout << "Addition Of Two Number is:" << c << endl; return 0; }
cerr(Standard Error stream):
- The predefined object Standard Error stream(cerr) is an instance of the ostream class.
- The object is said to be the standard error device.
- Used in conjunction with the stream insertion operator.
- It is written as cerr <<.
Example for cerr:
#include <iostream> using namespace std; int main() { char ch[] = "Unable to read...."; cerr << "Error message : " << ch << endl; return 0; }
endl(Standard End Line):
- The predefined object Standard End Line(endl) is an instance of the ostream class.
- ENDL helps to insert a new line character.
Example for endl:
#include <iostream> using namespace std; int main() { int a,b,c; cout << "Enter the numbers:"; cin >> a >> b; c=a+b; cout << "Addition Of Two Number is:" << c << endl; return 0; }
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.