gpt4 book ai didi

c++ - 使用 scanf 的奇怪输出

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:56:52 26 4
gpt4 key购买 nike

#include <cstdio>  

int main()
{
int i;
printf("%d", scanf("%d", &i));
}

无论我输入什么数字,我都会得到输出:

1

为什么会这样?

最佳答案

成功后,scanf功能

returns the number of items successfully read.

如果发生匹配失败,此计数可以匹配预期的读数或更少,甚至为零。如果在成功读取任何数据之前输入失败,EOF被退回。

也试试这个:

printf("%d",scanf("%d%d",&i,&i));

关于c++ - 使用 scanf 的奇怪输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5754134/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com