cout is an object in C used to output data on the console. Its output methods include: using the insertion operator (<<) to output data. Call member functions such as put() to output a single character, write() to output a string or array, and flush() to force the output buffer to be flushed.
How to use cout in C
What is cout?
cout is an object in the C standard library used to output data on the console.
Usage method
There are two main ways to use cout to output data:
Use the insertion operator (<) to output data to the cout stream. For example:
cout << "Hello, world!" << endl; // 输出 "Hello, world!" 字符串
cout object also provides several member functions for outputting data, for example:
Example
The following code demonstrates the use of the cout object:
#include <iostream> using namespace std; int main() { cout << "Enter your name: "; string name; getline(cin, name); cout << "Hello, " << name << "!" << endl; return 0; }
Note: The
The above is the detailed content of How to use cout in c language. For more information, please follow other related articles on the PHP Chinese website!