当前位置: 技术问答>linux和unix
缓冲流定向的问题
来源: 互联网 发布时间:2016-12-19
本文导语: #include #include int main() { FILE *fp; char buffer[100]; if ((fp = fopen("1.txt", "w+")) == NULL) { printf("fopen error!n"); } setbuf(fp, NULL); //设置为不带缓冲 if (setvbuf(fp, buffer, _IONBF, 20) _IO_f...
#include
#include
int main()
{
FILE *fp;
char buffer[100];
if ((fp = fopen("1.txt", "w+")) == NULL)
{
printf("fopen error!n");
}
setbuf(fp, NULL); //设置为不带缓冲
if (setvbuf(fp, buffer, _IONBF, 20) _IO_file_flags && _IO_LINE_BUF)
{
printf("line buffered!n");
}
else if (fp->_IO_file_flags && _IO_UNBUFFERED)
{
printf("NO buffe!n");
}
else
{
printf("Full buffer!n");
}
if (fclose(fp)
#include
int main()
{
FILE *fp;
char buffer[100];
if ((fp = fopen("1.txt", "w+")) == NULL)
{
printf("fopen error!n");
}
setbuf(fp, NULL); //设置为不带缓冲
if (setvbuf(fp, buffer, _IONBF, 20) _IO_file_flags && _IO_LINE_BUF)
{
printf("line buffered!n");
}
else if (fp->_IO_file_flags && _IO_UNBUFFERED)
{
printf("NO buffe!n");
}
else
{
printf("Full buffer!n");
}
if (fclose(fp)