看起来很简单的文件处理问题
我将buffer去处理后以二进制形式存放入文件。可发现写入一个0x0a后再次打开文件时发现变成了0x0d,0x0a。这个0x0d是哪儿来的,平台是windows xp(e), 工具vc6.0 问题点数:50、回复次数:7Top
1 楼DentistryDoctor(不在无聊中无奈,就在沉默中变态)回复于 2005-01-04 11:48:47 得分 0
\n=>\r\nTop
2 楼lsgt(天下第七)回复于 2005-01-04 11:53:50 得分 25
是不是用的二进制形式哦。我上次用文本格式写进去就会这样。
FILE* f=fopen(szName,"ab")这样应该不会Top
3 楼HunterForPig(留着口水的猪)回复于 2005-01-04 11:54:07 得分 0
0x0d,0x0a 对应ascii码的回车,换行Top
4 楼welcome_ck(C.k.)回复于 2005-01-04 12:03:26 得分 0
0d是回车
0a是换行Top
5 楼bluestone(kulawa)回复于 2005-01-04 12:17:06 得分 25
以二进制方式读写文件就不会出现这种问题,以文本方式读写文件时,API会自动转换一些特殊含义的字符。二进制方式->"b"Top
6 楼sunvin(星魄)回复于 2005-01-04 13:10:26 得分 0
"r" open text file for reading
"w" create text file for writing; discard previous contents if any
"a" append; open or create text file for writing at end of file
"r+" open text file for update (i.e., reading and writing)
"w+" create text file for update, discard previous contents if any
"a+" append; open or create text file for update, writing at end
我用的是rb
Top
7 楼sunvin(星魄)回复于 2005-01-04 13:19:13 得分 0
的确用了wb就行了,散分了Top




