In C, you can use the printf function to output formatted data, but it is recommended to use the cout object in the iostream library. The syntax is printf(const char *format, ...), where format specifies the format, and ... is a variable parameter list containing the data to be output. Format specifiers (such as %d, %f, %s) control the output format.
Use of printf in C
printf is a function in the C language library, used to convert the format The transformed data is output to standard output (usually the console). In C, you can also use the printf function, but it is more recommended to use the iostream object provided by the C iostream library, such as cout.
Syntax
##printf(const char *format, ...);
: A format string that specifies the format of the output data.
: Variable parameter list containing the data to be output.
Format specifier
Format specifiers can be used in the format string to control the format of the output data. Some commonly used format specifiers include:: signed decimal integer
: unsigned decimal integer
: floating point number
: string
: character
Usage example
<code class="cpp">#include <cstdio> int main() { int age = 25; float salary = 10000.50; char name[] = "John Doe"; printf("年龄:%d\n", age); printf("工资:%.2f\n", salary); printf("姓名:%s\n", name); return 0; }</code>
<code>年龄:25 工资:10000.50 姓名:John Doe</code>
Note:
The above is the detailed content of How to use printf in c++. For more information, please follow other related articles on the PHP Chinese website!