linux 学习笔记之 Standard I/O Library

本文介绍了Linux标准I/O库中的缓冲类型,包括全缓冲、行缓冲和无缓冲,并通过setbuf和setvbuf函数设置缓冲。此外,讨论了fflush函数在刷新流中的作用。接着,讲解了如何使用freopen和fdopen打开流,以及读写流的注意事项和不同类型的I/O操作,如字符、行和直接I/O。最后,提到了每个标准I/O流与文件描述符的关系。
摘要由CSDN通过智能技术生成
  1. Buffereing

            Three types of buffereing provided:

  • Fully buffered. Files residing on disk are normally fully buffered by the standard I/O library.
  • Line buffered. Line buffering is typically used on a system when it refers to a terminal: standard input and standard output.
  • Unbuffered. It makes the data output as soon as possible. The standard error stream, for example, is normally unbuffered. This is so that any error messages are displayed as quickly as possible.
    void  setbuf(FILE  * fp,  char   * buf);
    void  setvbuf(FILE  * fp,  char   * buf,  int  mode, size_t size);
    This function must call after the stream has been opened but before any other operation is performed on the stream.
  • With setbuf, we can turn buffering on or off. To enable buffering, buf must point to a buffer of length BUFSIZ. To disable buffering, we set buf to NULL.
  • With setvbuf, We specify exactuly which type of buffering we want. This is done with the mode argument: _IOFBUF -> fully buffered, _IOLBUF -> line buffered, _IONBUF -> unbuffered. The size argument equal the length of the buf.
  • In general, we should let the system choose the bufer size and automatically all
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值