2010年9月8日星期三

用fflush刷新输出流

1:
源代码:

#include    <stdio.h>

int main(int argc, char *argv[])
{
    printf("Hello,world");
    sleep(30);      //等待30s

    return 0;
}
执行结果:等待30s,输出hello,world

2:
#include    <stdio.h>

int main(int argc, char *argv[])
{
    printf("Hello,world\n");
    sleep(30);

    return 0;
}
执行结果:输出hello,world,然后等待30s.
注意:1和2的区别在于,2中有“\n”

3:
#include    <stdio.h>

int main(int argc, char *argv[])
{
    printf("Hello,world");
    fflush(stdout);
    sleep(30);

    return 0;
}
执行结果:输出hello,world,然后等待30s

fflush将缓冲区清除

没有评论:

发表评论