gcc下fflush(stdin)无效的解决

华为OD机试真题 新系统 2026-04-26 Python&JS 实现【最大化游戏试玩资格分发】 新研发了一台游戏设备可以面向用户接受试玩。现有 n 个试玩申请,每个试玩有开始时间和结束时间。作为协调员,为了能让更多人体验到游戏,你需要对试玩申请进行选择,使得: 阅读详情
今天编译一程序涉及到了键盘缓冲区的清除问题,在VC下完全没问题的代码却不能在gcc下运行成功,作此笔记以留念:  
VC下代码:  
#include<stdio.h>  
void main()  
{  
        float a,b;  
        int tag=0;  
        char ch;  
        float result;  

        printf("Input two number:");  
        scanf("%f%f",&a,&b);  
        fflush(stdin);  
        printf("Input arithmetic lable(+-*/):");  
        scanf("%c",&ch);  

        switch (ch)  
        {  
                case '+':result=a+b;break;  
                case '-':result=a-b;break;  
                case '*':result=a*b;break;  
                case '/':if(!b)  
                         {  
                                 printf("divisor is zero!\n");  
                                 tag=1;  
                         }  
                         else  
                                 result=a/b;  
                         break;  
                default:printf("illegal arithmetic lable\n");  
                        tag=1;  
        }  
        if(!tag)  
                printf("%.2f %c %.2f=%.2f\n",a,ch,b,result);  
}  

一网友的解释如下:

如何清除stdin缓存中的数据?

一。这问题没有什么很标准的做法:
方法1、fflush(): VC上面使用fflush()可以成功, 而在gcc上面使用fflush()却不能成功。
方法2、setbuf(): 虽然在gcc上面,使用这种方式确实可以清空输入流. 但不建议使用。
方法3、通过 while 循环把输入流中的余留数据“吃”掉:
        int c;
        while ((c=getchar()) != '\n' && c != EOF);
(使用while(getchar()!='\n') 也可以 )
        /*可直接将这2句代码当成fflush(stdin)的替代,直接运行可清除输入缓存流*/

二。解释:

1. fflush()不行的原因如下:

C-FAQ中如下:
Question 12.26
How can I flush pending input so that a user's typeahead isn't read at the next prompt? Will fflush(stdin) work?

--------------------------------------------------------------------------------
fflush is defined only for output streams. Since its definition of ``flush'' is to complete the writing of buffered characters (not to discard them), discarding unread input would not be an analogous meaning for fflush on input streams.

There is no standard way to discard unread characters from a stdio input stream, nor would such a way be sufficient unread characters can also accumulate in other, OS-level input buffers.

C标准(ISO/IEC 9899:1999 standard)规定fflush(stdin)操作是未定义的<参看《ISO/IEC 9899:1999 standard》p270>;。也就是说不一定能实现刷新功能,但有的编译器可能不遵循标准,对fflush(stdin)操作不予警告,并且有时可能产生正确的结果,但最好不要这样使用。
VC上面使用fflush()可以成功, 而在gcc上面使用fflush()却不能成功。


以下是 C99 对 fflush 函数的定义:

int fflush(FILE *stream);
如果 stream 指向输出流或者更新流(update stream),
并且这个更新流最近执行的操作不是输入,
那么 fflush 函数将把这个流中任何待写数据传送至宿主环境(host environment)写入文件。
否则,它的行为是未定义的。

原文如下:
int fflush(FILE *stream);
If stream points to an output stream or an update stream in which
the most recent operation was not input, the fflush function causes
any unwritten data for that stream to be delivered to the host environment
to be written to the file; otherwise, the behavior is undefined.

其中,宿主环境可以理解为操作系统或内核等。

由此可知,如果 stream 指向输入流(如 stdin),那么 fflush 函数的行为是不确定的。故而使用 fflush(stdin)   是不正确的,至少是移植性不好的。

2. setbuf()的方法也是不符合标准的. 虽然在有些场合它通过将输入设置为无缓冲形式, 以此来刷新输入流, 但是不太可靠。
虽然在gcc上面,使用这种方式确实可以清空输入流. 但不建议使用. 
 

其编译后不能运行成功的主要原因在于gcc下fflush(stdin)没起作用,所以   
     printf("Input two number:");  
        scanf("%f%f",&a,&b);  
        fflush(stdin);  
        printf("Input arithmetic lable(+-*/):");  
        scanf("%c",&ch);  
可以改为:  
printf("Input two number:");  
scanf("%f%f",&a,&b);  
printf("Input arithmetic lable(+-*/):");  
scanf("  ");  
scanf("%c",&ch);  

这样在gcc下即可编译执行成功,不足之处望指正共同进步。。。。。 

转自: http://hi.baidu.com/agassi_p/blog/item/1e4801824e29a2b50df4d257.html

【华为OD机试真题 新系统】1010、魔法阵的能量收集 | 机试真题+思路参考+代码解析(C++、Java、Py、C语言、JS) 【华为OD机试真题 新系统】1010、魔法阵的能量收集 | 机试真题+思路参考+代码解析(C++、Java、Py、C语言、JS) 华为od机试,华为od机试真题,华为od机试E卷,华为odE卷,华为od机试真题E卷,华为OD,华为OD机试,华为OD机试真题,华为od机考,华为od机试D卷,华为od机试真题D卷,华为od手撕代码,华为od,华为od机试C卷,华为od e卷,华为2026e卷,od机试,2026E卷,华为OD机试E卷,什么是华为od,华为od介绍,全面了解华为od,2026华为od,如何备战华为 阅读详情

相关推荐

行政数据分析大屏实战:用Tableau从Excel到看板的完整搭建流程(含数据连接与字段计算避坑)

本文详细介绍了如何利用Tableau从Excel数据源搭建行政数据分析大屏的完整流程,涵盖数据准备、连接技巧、计算字段优化、看板设计及动态交互部署。通过五阶工作流,帮助用户高效处理多源异构数据,实现业务洞察与可视化呈现,提升行政数据分析效率。

weixin_29696711的博客 338

关于scanf和fflush(stdin)在VS中出现错误的原因

scanf_s需要额外传一个参数,表明最多读取的字符数,防止溢出。getchar()可以读取下一个字符,可以用来读scanf读取后留下的回车符以清空缓冲区。

night212的博客 1831

避免踩坑!WIN11 22H2更新后共享打印机失效的终极解决方案

本文详细解析了WIN11 22H2更新后共享打印机失效的问题,特别是常见的0x00000709错误代码。通过系统更新机制分析、错误代码解读,提供从基础到高级的完整解决方案,包括注册表修复、组策略调整和驱动兼容性处理,帮助用户彻底解决打印机共享问题并预防未来故障。

pp12345的博客 533

gcc下fflush(stdin)失效

今天编译一程序涉及到了键盘缓冲区的清除问题,在VC下完全没问题的代码却不能在gcc下运行成功,作此笔记以留念:  VC下代码:  #include  void main()  {          float a,b;          int tag=0;          char ch;          float result;          printf(

xinsuixiaofeiyu的专栏 2696

从门禁到支付:Uniapp+NFC开发避坑指南(支持Mifare Classic)

本文详细介绍了Uniapp结合NFC技术开发门禁与支付系统的实战指南,特别针对Mifare Classic卡片进行深度优化。内容涵盖环境配置、设备兼容性处理、卡片安全机制解析以及高性能读写优化策略,帮助开发者快速实现跨平台的智能硬件交互解决方案。

t1u2v的博客 751

【PointNet++】使用Open3D对分割后的结果可视化

PointNet++中的局部分割网络预测后是没有可视化文件的,所以需要自己通过编写Open3D或者PCL点云算法去可视化,在本人经过查找翻阅修改后,实现了网络输出点云分割后结果的可视化。已实现推测单个点云,并可视化。

纵马踏花向自由 2453

为什么fflush(stdin)用了并不能清除缓冲区

为什么fflush(stdin)用了并不能清除缓冲区 很多人在教材上都看到fflush(stdin)这个函数的使用,教材给出的解释是清除缓冲区,可是一些动手实践过代码的小伙伴发现,fflush(stdin)这个函数并没有起到清除缓冲区的作用,那这是什么原因呢? 教材中fflush(stdin)的来源 fflush(stdin)这个函数官方给出的解释是:由Microsoft官方提供的MSDN 文档里...

蜗小牛的博客 3万+

电商数据采集实战——多平台价格监控、比价分析与智能告警系统

在电商竞争日益激烈的今天,价格监控与比价分析已成为品牌商、渠道商和消费者的核心需求。对于品牌商而言,需要监控各渠道售价是否低于指导价(破价监控);对于消费者而言,希望在最佳时机以最低价购入心仪商品;对于数据分析师而言,价格波动数据是洞察市场趋势的金矿。然而,电商数据采集面临三大核心挑战:本文将基于 Python + Scrapy + Playwright + Redis + ClickHouse 技术栈,构建一套完整的电商价格监控与比价系统。架构分层说明:电商平台的反爬手段层出不穷,采集系统必须具备多层次的

从事移动开发八年,csdn博客专家,阿里云特邀专家,华为云云享专家,高级网络信息安全工程师,大数据工程师(高级),python技术开发(高级),HarmonyOS 应用开发者高级认证,现在某学校任教。 136

C语言中fflush()、fflush(stdin)、fflush(stdout)

头文件:#include&lt;stdio.h&gt; fflush()不是标准库文件,经笔者测试,VC6.0完美支持,GCC(GCC4.6.2)不支持。 fflush()用于清空文件缓冲区,如果文件是以写的方式打开 的,则把缓冲区内容写入文件。其原型为: int fflush(FILE* stream); 【参数】stream为文件指针。 【返回值】成功返回0,失败返回EOF,错误代码存...

杨氏计算机知识整理 3万+

把数据库事务边界握在手里:ABAP 里的 COMMIT CONNECTION 与 ROLLBACK CONNECTION 深度拆解

与表面是两条很短的语句,背后却牵动了连接管理、数据库 LUW、SAP LUW、隐式提交、游标生命周期、GTT 平台差异等一整片工程现实。把它们用对,你就能在不破坏主业务事务的前提下,实现跨库写入、审计落库、隔离型日志、数据集成落地等一系列“看似矛盾”的目标;用错了,它们也会悄无声息地制造一致性缺口,让问题在高峰期以 dump 或数据异常的方式爆出来。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1841

一文速学数模-K-means聚类算法实战:信用卡用户画像聚类分析

该项目算是非常经典的金融业务用户画像的基础分析了,主要根据用户信用卡使用行为数据进行分析,根据收集到的不同字段信息,对每个用户划分类别。这里需要说明一下的是,聚类模型只是将具有相似行为的大部分用户聚集到一个类别里面,这点并不会考虑到每个字段的含义,也就是分成的类别并不是用户价值等级,此类别仅仅是这个类别大体相同的信用卡用户行为对象,并不能给每个用户价值打上标签,那是评价模型做的事,这里要注意不要搞混淆了,用户价值评价是评价模型决定的,而画像是聚类模型分析的。

master_hunter的博客 1万+

fflush(stdin)引起的问题

今天在调试一段输入程序时,偶然发现scanf()输入函数缓冲区残留的问题。 网上转了一大圈,大家都说用fflush(stdin)进行强制刷新,但是在LINUX上的GCC不起什么作用。 于是加到了以下文章,对fflush()函数进行了深度分析,分享一下。 文章转至:http://my.oschina.net/deanzhao/blog/79790 1. 为什么 fflush(st

kang99827765的专栏 9469

五十天精通硬件设计第6天-放大器知识及选型

运算放大器(Operational Amplifier,简称运放)是一种高增益的直流耦合差分放大器,广泛应用于信号处理、滤波、比较、积分、微分等电路中。

whm128的博客 596

gcc下fflush失效

今天编译一程序涉及到了键盘缓冲区的清除问题,在VC下完全没问题的代码却不能在gcc下运行成功,作此笔记以留念: VC下代码: #include<stdio.h> void main() { float a,b; int tag=0; char ch; float result; printf("Input two number:"); scanf("%f%f",&a,&b); fflush(stdin); printf("Input arit

m0_51647314的博客 1343

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

fflush(stdin)函数在linux下无效

今天在编程的时候发现一个有关fflush刷新缓冲区问题: #include&lt;stdio.h&gt; int main(int argc, char const *argv[]) { char c; int number; scanf("%d",&amp;number); fflush(stdout); c = getchar(); putchar(c); return 0; }...

Yannie's Blog 1244

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

C 清空输入缓冲区,以及fflush(stdin)的使用误区和解决方法

对C 语言初学者来说,fflush(stdin)函数被解释为会清空输入缓冲区的一个系统函数,这是一个曾经几乎对过一半的说法,随着计算机科学的进步,在学习的过程中的逐步完善,将fflush(stdin)函数的过去与现在分析一下。Personal thinking:fflush(stdin) 会清空输入缓冲区中的内容,读取时输入缓冲区中的内容会被scanf函数逐个取走,正常case下scanf()函数可

Veniversum的博客 2万+

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

理解:fflush(stdin)和fflush(stdout)和rewind(stdin)的区别和作用

理解:fflush(stdin)和fflush(stdout)和rewind(stdin) 小结论(多谢网友zhao4zhong1为我解答疑难): 1、在每个最后不带\n的printf后面加fflush(stdout);(对标准输出流进行清理,但是它并不是把数据丢掉,而是及时地打印数据到屏幕上。) 2、在每个不想受到输入(接收)缓冲区旧内容影响的scanf();【或者getchar();或者

dsli123的专栏 9852

GCC中gets()/fges()读入输入的问题解决 -- 清理stdin缓存

这几天一直被一个bug折磨,最终发现是stdin缓存了‘\n’,因此fgets()函数无法正常执行,解决的方法是在调用fgets()之前将缓存清空。VC中可以使用fflush(stdin)的方法,但在gcc中,fflush(stdin)的作用并不是清空stdin缓存,因此需要我们手动来做,代码如下: 代码说明:         这段代码的目的是读入矩阵的行、列数,然后让用户一次性输入整个矩阵。

jubincn的专栏 2916

fflush(stdout)和fflush(stdin)

fflush是一个在C语言标准输入输出库中的函数,功能是冲洗流中的信息,该函数通常用于处理磁盘文件。fflush()会强迫将缓冲区内的数据写回参数stream 指定的文件中。 1、fflush(stdout) fflush(FILE p)是把FILEp指向的流的输出立即写入并清空,所以加上fflush(stdout)就是立即显示到屏幕上。 #include<stdio.h> #include<stdlib.h> #include<unistd.h> void main(

weixin_46721287的博客 1155

【fflush】Linux环境下清空标准输入缓冲区 fflush(stdin) 无效

文章目录一、误区二、问题描述三、解决方法四、原因 一、误区 不论从 字面意思 还是 某些技术文档 中,都可以看到 fflush(stdin) 是对标准输入缓冲区清空的标准方案; 然而,并不是! 深入了解一下 fflush(stdin) 之后,才发现这个锅得自己背,怪自己喜欢拿来就用,不去深入了解某些重要细节,给自己上了生动一课; 二、问题描述 环境:Ubuntu18.04 编译器:gcc v...

问题不大 5917

fflush()函数总结

1. 概述 函数名: fflush() 功 能: 清除读写缓冲区,需要立即把输出缓冲区的数据进行物理写入时 头文件: stdio.h 原型: int fflush(FILE *stream),其中stream是要冲洗的流 2. 函数说明 fflush()会强迫将缓冲区内的数据写回参数stream 指定的文件中. 如果参数stream 为NULL,fflush()会将所有打开的文...

dijingzhou4259的博客 2746

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

理解:fflush(stdin)和fflush(stdout)和rewind(stdin) 小结论(多谢网友zhao4zhong1为我解答疑难): 1、在每个最后不带\n的printf后面加fflush(stdout);(对标准输出流进行清理,但是它并不是把数据丢掉,而是及时地打印数据到屏幕上。) 2、在每个不想受到输入(接收)缓冲区旧内容影响的scanf();【或者getchar();或者get...

AplusX 1719

实现算法过程中的小经验——关于fflush(stdin)的使用

关于fflush(stdin)的使用 #include <stdio.h> #include <stdlib.h> int main() { int i; for(;;) { fputs("Please input an integer: ", stdout); scanf("%d", &i); printf("%d\n", i); } return 0; } 这个程序首先会提示用户输入一个整数,然后等待用户输入,如果用户

shy-2的博客 756

fflush(stdin) 和 fflush(stdout)

转自:百度百科:http://baike.baidu.com/view/656650.htm  和  http://www.cnitblog.com/wujian-IT/archive/2007/10/15/34891.aspx 概述   函数名: fflush   功 能: 清除文件缓冲区,文件以写方式打开时将缓冲区内容写入文件   头文件:   原型:int

zwj525的专栏 976

Linux下不能使用fflush(stdin)

标准规定fflush()函数是用来刷新输出(stdout)缓存的。对于输入(stdin),它是没有定义的。GCC编译器没有定义它的实现,所以不能使用fflush(stdin)来刷新输入缓存。 如果需要清空stdin,我们可以通过读取剩余的字符来实现: char ch; while((ch = getchar()) != '\n' && ch != EOF); ...

qwerty559的博客 551
上一篇: 为Vim 添加vimgdb支持
下一篇: 如何计算时间复杂度
ly0303521
博客等级 码龄17年 135粉丝 90原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值