std::cout (C++)

std::cout is C++'s standard output stream, used to print text and values to the console. You send data to it with the << insertion operator.

C++

cout lives in the <iostream> header and the std namespace. You can chain multiple values together with <<, and use std::endl or "\n" to move to a new line.

It is the C++ equivalent of print() in Python and console.log() in JavaScript.

Syntax

std::cout << value << std::endl;

Examples

C++

#include <iostream>

int main() {
    int age = 20;
    std::cout << "Age: " << age << std::endl;
    return 0;
}

Output:

Age: 20

Learn it in a lesson

See also

Back to the Dictionary