Cout format in c++
- how to cout a string in c++
- how to output a string in c++
- how to count a string in c++
- how to count substring in a string in c++
How to print a string in c++ using cout
How to print string in c++!
cout in C++
In C++, cout is an object of the ostream class that is used to display output to the standard output device, usually the monitor. It is associated with the standard C output stream stdout.
The insertion operator (<<) is used with cout to insert data into the output stream.
Let’s take a look at an example:
Syntax of cout
cout << var_name;
Here,
- <<: It is the insertion operator used to insert data into cout.
- var_name: It represents the variable or literal whose value you want to display.
Examples of cout in C++
The below programs demonstrate how to use the cout for output purposes in C++.
Print Hello World
Displaying Multiple Variables
cout Member Functions in C++
Below is a list of some commonly used member functions of cout in C++:
Member Function | Description |
---|---|
cout.put(char) | Writes a single character to the output stream. |
cout.write(char*, int) | Writes a block of characters from the array to the output stream. |
cout.precision(int) | Sets the decimal precision for displaying floating-poin
|