缓冲区:
分为三种:空缓冲,行缓冲,全缓冲。
1.空缓冲: 没有缓冲,也就是信息在输入输出的时候,立马输入或输出。(eg:标准错误流stderr)
2.行缓冲: 当输入输出的时候,遇到换行才执行I/O操作。(eg:键盘的操作)
3.全缓冲: 当输入输出写满缓冲区才执行I/O操作。(eg:磁盘的读写)
几种情况及其现象:
1.
#include <stdio.h>
#include <unistd.h>
int main()
{
printf("hehe ");
sleep(3);
return 0;
}
现象:停了3秒之后显示hehe,并没有换行
2.
#include <stdio.h>
#include <unistd.h>
int main()
{
printf("hehe \n");
sleep(3);
return 0;
}