📄 subject_17504.htm
字号:
<p>
序号:17504 发表者:progame 发表日期:2002-10-11 21:23:19
<br>主题:吓我一跳,还以为菜鸟论坛不见,问个fstream问题
<br>内容:为什么以二进制方式写进int值会变成这样?<BR> fout <<filehead->length ;<BR> fout <<filehead->elementcount ;<BR><BR>length和elementcount皆为int型,数值分别是34949和175<BR><BR>我的文件打开方式为<BR> fout->open(destfile,<BR> ios::out |ios::trunc |ios::binary |ios::app ,<BR> filebuf::sh_read );<BR><BR>可是文件中却成了34979175,怎么直接写了字符?<BR>对应十六进制为:3334393439313735<BR><BR>我使用:<BR> fin >>filehead->length ;<BR> fin >>filehead->elementcount ;<BR>读取时,第一个值就读成了34979175<BR><BR>我该怎么办?谢谢! <BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:黄飚 回复日期:2002-10-11 23:24:25
<br>内容:Debug进去看一下
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:阿鬼 回复日期:2002-10-11 23:28:37
<br>内容:fstream基于char的<BR>看看这个明白了<BR>typedef basic_ios<char, char_traits<char> > ios;<BR>typedef basic_ifstream<char, char_traits<char> > ifstream;<BR>typedef basic_ofstream<char, char_traits<char> > ofstream;<BR><BR>你想实现你的功能,需要这个<BR>fopen<BR>fwrite<BR>fread<BR>fclose<BR><BR>eg:<BR> char *destfile = "c:\\test.txt";<BR> FILE *f = fopen( "c:\\test.txt", "w" );<BR> int buffer = 34949;<BR> fwrite( &buffer, sizeof(int), 1, f );<BR> fclose( f );<BR>里面会存为 85 88 00 00<BR>读取只要根据size就可以区分了
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -