Std::cout
Jump to navigation
Jump to search
Syntax
extern ostream cout;
Description
Standard output stream
Object of class ostream that represents the standard output stream oriented to narrow characters (of type char). It corresponds to the C stream stdout.
The standard output stream is the default destination of characters determined by the environment. This destination may be shared with more standard objects (such as cerr or clog).
As an object of class ostream, characters can be written to it either as formatted data using the insertion operator (operator<<) or as unformatted data, using member functions such as write.
The object is declared in header <iostream> with external linkage and static duration: it lasts the entire duration of the program.
Example
Note: both below sources are identical.
Source 1 | Source 2 |
---|---|
#include <iostream>
int main()
{
std::cout << "Hello world" << std::endl << "How are you?" << std::endl;
return 0;
}
|
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world" << endl;
cout << "How are you?" << endl;
return 0;
}
|
Run
$ ./main Hello world How are you?