⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subject_17504.htm

📁 一些关于vc的问答
💻 HTM
字号:
<p>
序号:17504 发表者:progame 发表日期:2002-10-11 21:23:19
<br>主题:吓我一跳,还以为菜鸟论坛不见,问个fstream问题
<br>内容:为什么以二进制方式写进int值会变成这样?<BR>&nbsp;&nbsp;&nbsp;&nbsp;fout &lt;&lt;filehead-&gt;length&nbsp;&nbsp;;<BR>&nbsp;&nbsp;&nbsp;&nbsp;fout &lt;&lt;filehead-&gt;elementcount ;<BR><BR>length和elementcount皆为int型,数值分别是34949和175<BR><BR>我的文件打开方式为<BR>&nbsp;&nbsp;&nbsp;&nbsp;fout-&gt;open(destfile,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ios::out |ios::trunc |ios::binary |ios::app ,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;filebuf::sh_read&nbsp;&nbsp;);<BR><BR>可是文件中却成了34979175,怎么直接写了字符?<BR>对应十六进制为:3334393439313735<BR><BR>我使用:<BR>&nbsp;&nbsp;&nbsp;&nbsp;fin &gt;&gt;filehead-&gt;length&nbsp;&nbsp;;<BR>&nbsp;&nbsp;&nbsp;&nbsp;fin &gt;&gt;filehead-&gt;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&lt;char, char_traits&lt;char&gt; &gt; ios;<BR>typedef basic_ifstream&lt;char, char_traits&lt;char&gt; &gt; ifstream;<BR>typedef basic_ofstream&lt;char, char_traits&lt;char&gt; &gt; ofstream;<BR><BR>你想实现你的功能,需要这个<BR>fopen<BR>fwrite<BR>fread<BR>fclose<BR><BR>eg:<BR>&nbsp;&nbsp;&nbsp;&nbsp;char *destfile = "c:\\test.txt";<BR>&nbsp;&nbsp;&nbsp;&nbsp;FILE *f = fopen( "c:\\test.txt", "w" );<BR>&nbsp;&nbsp;&nbsp;&nbsp;int buffer = 34949;<BR>&nbsp;&nbsp;&nbsp;&nbsp;fwrite( &buffer, sizeof(int), 1, f );<BR>&nbsp;&nbsp;&nbsp;&nbsp;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 + -