计算文件的长度

1、FIO19-C. Do not use fseek() and ftell() to compute the size of a regular file

2、Reposition stream position indicator

遇到的问题:

①多次执行fopen("wb"),会清空文件的内容。如果需要多次打开一个文件并写入的话,后面的写入需要使用fopen("a+") appendend,或者尽量在在一次fopen中将文件写完。

w+ Open for reading and writing. The file is created if it does not exist, otherwise it is truncated,. The stream is positioned at the beginning of the file. 如果文件以前不存在,那么会创建一个,否则文件会被 截短/truncated或者清空流/stream
REFER: fopen(3) - Linux man page

这个问题在很多语言中都会碰到,到底是w+模式,还是a+模式

posted @ 2016-10-31 16:31  xiulug  阅读(414)  评论(0编辑  收藏  举报