- r 只读
- w 只写,清空原有内容,文件不存在会创建
- a 追加只写,
- w+ 读写, 清空原有内容,文件不存在会创建
- r+ 读写, 保留原有内容
- a+ 追加读写,(和r+不同的地方,fseek only sets the read pointer,即只能改变读指针,写都是从文件尾追加)
That's because in a mode, writing to the FILE* always appends to the end. fseek only sets the read pointer in this mode.
Opening a file with append mode ('a' as the first character in the mode argument) causes all subsequent writes to the file to be forced to the then current end-of-file, regardless of intervening calls to the fseek function.