cout in C++
The cout object in C++ is an object of class ostream. It is defined in iostream header file. It is used to display the output to the standard output device i.e. monitor. It is associated with the standard C output stream stdout. The data needed to be displayed on the screen is inserted in the standard output stream (cout) using the insertion operator(<<).
Below is the C++ program to implement cout object:
Welcome to GFG
Note: More than one variable can be printed using the insertion operator(<<) with cout.
Below is the C++ program to implement the above approach:
Name : Akshay Age : 18
The cout statement can also be used with some member functions:
- cout.write(char *str, int n): Print the first N character reading from str.
- cout.put(char &ch): Print the character stored in character ch.
- cout.precision(int n): Sets the decimal precision to N, when using float values.
Below is the implementation of the member functions of the cout.write() and cout.put():
Below is the C++ program to illustrate the use of cout.precision():