c-plus-plus
  1. c-plus-plus-cout

C++ Tutorial: cout

Syntax

cout << data;

Example

#include <iostream>
using namespace std;

int main() {
   int age = 27;
   cout << "My age is " << age << endl;
   return 0;
}

Output

My age is 27

Explanation

cout is the standard output stream in C++. It is used to display information on the console. The << operator is used to concatenate and display data on the console.

In the example above, the integer variable age is concatenated with the string "My age is " and displayed on the console using cout. The endl manipulator is used to insert a new line.

Use

cout is used extensively in C++ programming to display information on the console. It is often used for debugging purposes and for displaying the output of a program.

Important Points

  • cout is used to display information on the console in C++.
  • The << operator is used to concatenate and display data on the console.
  • The endl manipulator is used to insert a new line.

Summary

cout is a vital component of C++ programming. It is used to display information on the console and is essential for debugging and displaying program output. Remember to use the << operator and endl manipulator when displaying data on the console using cout.

Published on: