what is cin, cout, endl ?
In C++, cin
, cout
, and endl
are input/output (I/O) stream objects used for reading input from and writing output to the console.
cin
is used for reading input from the console, which can be any data type, including integers, floating-point numbers, characters, and strings. For example, to read an integer value from the console, we can use the following code:
int x; cin >> x;
Here, cin
reads the input value from the console and stores it in the variable x
.
cout
is used for writing output to the console. We can use cout
to output any data type to the console, including integers, floating-point numbers, characters, and strings. For example, to output the value of the variable x
to the console, we can use the following code:
cout << x;
Here, cout
outputs the value of x
to the console.
endl
is used to insert a newline character and flush the output buffer. It is typically used to move the cursor to a new line after outputting something to the console. For example, to output a string followed by a newline character to the console, we can use the following code:
cout << "Hello, world!" << endl;
Here, endl
inserts a newline character after the string “Hello, world!” and flushes the output buffer.