卓越飞翔博客卓越飞翔博客

卓越飞翔 - 您值得收藏的技术分享站
技术文章51371本站已运行31125

c++中scanf和printf用法

c++ 中 scanf 和 printf 函数用于从标准输入读取数据和向标准输出写入数据。scanf 用法:int scanf(format, ...),其中 format 为要读取的数据格式,... 为要读取的变量地址;printf 用法:int printf(format, ...),其中 format 为要写入的数据格式,... 为要写入的变量。

c++中scanf和printf用法

C++ 中 scanf 和 printf 用法

scanfprintf 是 C++ 中两个常用的标准输入/输出函数。它们用于分别从标准输入读取数据和向标准输出写入数据。

scanf

用法:

<code class="cpp">int scanf(const char *format, ...);

其中:

  • format:指定要读取的数据的格式字符串。
  • ...:要读取的变量的地址。

格式说明符:

  • %d:整数
  • %f:浮点数
  • %c:字符
  • %s:字符串

示例:

<code class="cpp">int age;
char name[50];
scanf("%d %s", &amp;age, name);

printf

用法:

<code class="cpp">int printf(const char *format, ...);

其中:

  • format:指定要写入的数据的格式字符串。
  • ...:要写入的变量。

格式说明符:

  • %d:整数
  • %f:浮点数
  • %c:字符
  • %s:字符串

示例:

<code class="cpp">int age = 25;
printf("姓名:%s,年龄:%dn", name, age);
卓越飞翔博客
上一篇: PHP 框架指南:探索不同框架的优势和差异
下一篇: 返回列表
留言与评论(共有 0 条评论)
   
验证码:
隐藏边栏