cout with Insertion Operator
The "c"in cout refers to "character" and "out" means "output". Hence cout means "character output". The cout object is used along with the insertion operator << in order to display a stream of characters.
The cout object is used along with the insertion operator << in order to display a stream of characters. For example,
#include <iostream>
using namespace std;
int main()
{
int var1 = 25, var2 = 50;
cout << var1;
cout << "Some String";
cout << var2;
The<< operator can be used more than once with a combination of variables, strings, and manipulators.
cout << var1 << "Some String" << var2 << endl;
cout with Member Functions
he cout object can also be used with other member functions such as put(), write(), etc. Some of the commonly used member functions are:
cout.put(char &ch):Displays the character stored bych.cout.write(char *str, int n): Displays the firstncharacter reading fromstr.cout.setf(option): Sets a given option. Commonly used options areleft,right,scientific,fixed, etc.cout.unsetf(option): Unsets a given option.cout.precision(int n): Sets the decimal precision tonwhile displaying floating-point values. Same ascout << setprecision(n).
Top comments (0)