1-标准IO库提供的三种类型的buffering:
- Fully buffered(全缓冲)
- Line buffered(行缓冲)
- unbuffered(无缓冲):典型标准错误流
2-行缓冲会遇到的两个问题:
- 遇到新行符号前填满了buffer
- 所有line-buffered和
unbufferedstream输入请求都会flushline-buffered的输出流
3-三个标准流采用哪种buffering:
- 标准error总是
unbuffered - 标准input/output 在
terminal device的时候是line buffered;否则是fully buffered
4-对于打开的流,有三种无形式IO(unformated IO):
Character-at-a-time I/O. We canreadorwriteone character at a time。Line-at-a-time I/O.If we want toreadorwritea line at a time, we use fgets and fputs.Direct I/O(binary I/O). This type of I/O is supported by thefreadandfwritefunctions. These two functions are often used forbinary fileswhere we read or write a structure with each operation.
5-getc和fgetc之间的差别?以及注意点?
getc宏
fgetc函数
1. getc的参数一定不能是有副作用的表达式
2. 可以使用fgetc的地址,作为函数指针传入其他function
3. 调用fgetc消耗的时间比getc长
6-一般文件的缓冲模式?
默认全缓冲
7-临时文件有哪些相关调用?
tmpnam,tempnam
tmpfile, mkstemp
8-tmpnam,tempname的缺点?
在返回唯一pathname和用该pathname创建临时文件之间有一段空隙。其他的进程可能在该空隙内用同样的pathname创建了文件。这样会导致严重的后果。

本文详细解析了标准IO库中三种类型的buffering机制:全缓冲、行缓冲和无缓冲,并探讨了行缓冲所面临的问题及解决办法。同时,阐述了不同标准流采用的buffering类型,以及对于打开的流提供了三种无形式IO的操作方式。最后,通过对比getc和fgetc的使用场景,以及解释了标准文件的默认缓冲模式。
9644

被折叠的 条评论
为什么被折叠?



