fflush是一个在C语言标准输入输出库中的函数,功能是冲洗流中的信息,该函数通常用于处理磁盘文件。fflush()会强迫将缓冲区内的数据写回参数stream 指定的文件中。

1、fflush(stdout)

fflush(FILE p)是把FILEp指向的流的输出立即写入并清空,所以加上fflush(stdout)就是立即显示到屏幕上。

#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>void main()
{char str[20];pid_t pid=getpid();printf("my id is :%d",pid);fflush(stdout);     // if delete this line, we can't see the pid we wantsprintf(str,"kill %d\n",pid);system(str);
}

这个程序若没有fflush(stdout)就不会看到pid的输出。

2、fflush(stdin)

第一个程序输入123abc+回车

#include <stdio.h>
#include <stdlib.h>
int main(){int a;char c;scanf("%d", &a);c = getchar();printf("a = %d, c = %c \n", a, c);return 0;
}

#include <stdio.h>
#include <stdlib.h>
int main(){int a;char c;scanf("%d", &a);fflush(stdin);c = getchar();printf("a = %d, c = %c \n", a, c);return 0;
}

其实,在这里没有区别,因为我实在Linux平台下编译的。这也是我后来才知道的,大家可以参考一下别人的解释

在windows VC下fflush(stdin)是可以实现的,但是linux下不可以。 C标准规定fflush()函数是用来刷新输出(stdout)缓存的。对于输入(stdin),它是没有定义的。但是有些编译器也定义了 fflush(stdin )的实现,比如微软的VC。其它编译器是否也定义了 fflush( stdin)的实现应当查找它的手册。GCC编译器没有定义它的实现,所以不能使用 fflush( stdin )来刷新输入缓存。

fflush(stdout)和fflush(stdin)相关推荐

  1. fflush(stdin)和fflush(stdout)和rewind(stdin)的区别和作用

    理解:fflush(stdin)和fflush(stdout)和rewind(stdin) 小结论(多谢网友zhao4zhong1为我解答疑难): 1.在每个最后不带\n的printf后面加fflus ...

  2. fflush(stdin)和fflush(stdout)

    fflush(stdin)比较容易理解,即清理标准输入流,把多余的仍未被保存的数据丢掉. 比如,下面这个小程序: void main() { int a; char str[10]; cin>& ...

  3. fflush(stdin)与fflush(stdout)

    1.fflush(stdin): 作用:清理标准输入流,把多余的未被保存的数据丢掉.. 如: int main() {int num;char str[10];cin>>num;cout& ...

  4. 清空缓冲区:fflush(stdin)、fflush(stdout)

    fflush(stdin)用来清理输入缓冲区,平时用scanf()输入数据后会按回车,一般用fflush(stdin)来清理输入缓冲区,不然有时候该回车符会影响到后面的数据输入. fflush(std ...

  5. Linux环境编程--fflush(stdout)有什么作用

    代码: printf("hello\n"); //fflush(stdout); fork(); 输出: hello 代码: printf("hello\n") ...

  6. python中sys.stdout、sys.stdin

    如果需要更好的控制输出,而print不能满足需求,sys.stdout,sys.stdin,sys.stderr就是你需要的. 1. sys.stdout与print: 在python中调用print ...

  7. Python的sys.stdout、sys.stdin重定向

    Python的sys.stdout.sys.stdin重定向 转自:http://www.cnblogs.com/turtle-fly/p/3280519.html 本文环境:Python 2.7 使 ...

  8. fflush(stdout)作用

    头文件:#include<stdio.h>定义函数:int fflush(FILE * stream); 函数说明:fflush()会强迫将缓冲区内的数据写回参数stream指定的文件中, ...

  9. php fflush失败,php fflush 函数_PHP教程

    php fflush 函数 fflush ( PHP 4中" = 4.0.1 , PHP 5中) fflush -刷新输出到一个文件 描述 布尔fflush (资源$处理) 此功能部队写入所 ...

  10. Codeforces Round #720 (Div. 2) C. Nastia and a Hidden Permutation 交互

    传送门 文章目录 题意: 思路: 题意: 给你一个序列ppp长度nnn,每次可以执行两个种询问: t=1max(min(x,pi),min(x+1,pj))t=1\ \ max(min(x,p_i), ...

最新文章

  1. ios玩全民奇迹不显示服务器,全民奇迹关于IOS充值游戏物品不到账公告
  2. html 可以折叠的表格,javascript – html5 – 如何折叠和扩展复杂的表格元素
  3. 周杰伦入局元宇宙? 6200万个联名「幻象熊」40分钟全卖光!
  4. 因果解释能够对规则进行解释吗?
  5. 关于node.js的web框架的应用及并发性能测试
  6. Code:blocks 调试经历,调试成功这其一
  7. 声学漫谈之六:音腔频段如何判定?
  8. fusionsphere的核心组件_FusionSphere架构详解
  9. CVPR 2020 细粒度分类挑战赛冠军方案:数据增强+知识蒸馏,效果大幅提升
  10. C++Builder STL 泛型
  11. C#笔记之又谈装箱与拆箱(boxing and unboxing)
  12. 最完整Android Studio插件整理 (转)
  13. 游戏使用html签名,利用HTML5实现电子签名板文字涂鸦代码
  14. web前端@css选择器
  15. php网站登录界面验证码打不开,php网站无法显示验证码
  16. 【C++】C++中头文件使用双引号与书名号的区别
  17. The Apache Way - 开源项目
  18. webstorm 一次Git使用很卡的处理记录
  19. JS-108~161
  20. 师兄新作!Cell Stem Cell背靠背 | 吴军等建立了一种全新的全能干细胞

热门文章

  1. 使用Yomail的时候出现的错误解决方案
  2. 获取当天时间相关时间(凌晨、第二天凌晨)
  3. linux OOM killer分析
  4. 神经网络在控制中的作用,神经网络控制基本原理
  5. [Codeforces 274E]:Mirror Room(模拟)
  6. 拆解PowerApps - 请假申请 - 4
  7. EagleEye的特性分析
  8. Flurry使用初级教程
  9. (P24)进程间通信介绍二:死锁 ,信号量与PV原语 ,用PV原语解决司机与售票员问题 ,用PV原语解决民航售票问题 ,用PV原语解决汽车租赁问题
  10. 2020-09-12