zoukankan      html  css  js  c++  java
  • ffush的使用

    fflush是标准C语言输入输出的拓展,它的作用是刷新输入输出流:
    *对于输入流如stdin,调用fflush之后会清空输入缓冲区的内容。
    *对于输出流如stdout,调用fflush之后会将输出缓冲区的内容写入到对应文件中。

    #include <stdio.h>
    #include <conio.h>
    
    int main(void)
    {
        int integer;
        char string[81];
    
        printf("Enter a sentence of four words with scanf: ");
        for (integer = 0; integer < 4; integer++)
        {
    	scanf_s("%s", string, sizeof(string));
    	printf("%s\n", string);
        }
        fflush(stdin);//此处如果不进行刷新流,那么下面的get_s语句将直接从缓冲区中得到数据,而不会在从命令行等待输入。
        printf("Enter the same sentence with gets: ");
        gets_s(string, sizeof(string));
        printf("%s\n", string);
    
    }
  • 相关阅读:
    Codeforces 376A. Night at the Museum
    Assigning Workstations
    树的直径证明
    Frogger
    Circle
    HDU 1022 Train Problem I
    Argus
    树状数组总结
    C++ 容器(一):顺序容器简介
    C++ 输出缓冲区的管理
  • 原文地址:https://www.cnblogs.com/liujshi/p/5575885.html
Copyright © 2011-2022 走看看