C++ cout

manzura_kerimova

Kerimova_Manzura

Posted on March 10, 2023

C++ cout

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;

Enter fullscreen mode Exit fullscreen mode

The<< operator can be used more than once with a combination of variables, strings, and manipulators.

cout << var1 << "Some String" << var2 << endl;
Enter fullscreen mode Exit fullscreen mode

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 by ch.

  • cout.write(char *str, int n): Displays the first n character reading from str.

  • cout.setf(option): Sets a given option. Commonly used options are left, right,scientific, fixed, etc.

  • cout.unsetf(option): Unsets a given option.

  • cout.precision(int n): Sets the decimal precision to n while displaying floating-point values. Same as cout << setprecision(n).

πŸ’– πŸ’ͺ πŸ™… 🚩
manzura_kerimova
Kerimova_Manzura

Posted on March 10, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related