In C++, cout
is an object used for output, part of the <iostream>
library. It allows you to print text, variables, or expressions to the standard output (usually the console).
Here’s a basic example:
#include <iostream>
int main() {
int number = 5;
std::cout << "Hello, World!" << std::endl; // Print a string
std::cout << "The number is: " << number << std::endl; // Print a variable
return 0;
}
Key points:
std::cout
is used for printing output.- The
<<
operator is used to send data tostd::cout
. std::endl
inserts a newline character and flushes the output buffer, though\n
can also be used to add a newline.
You typically include <iostream>
to use std::cout
and other I/O features.
Is there something specific about cout
you’re curious about?