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

📄 subject_50864.htm

📁 一些关于vc的问答
💻 HTM
字号:
<p>
序号:50864 发表者:lzy59418 发表日期:2003-08-27 10:59:51
<br>主题:我在程序中的文件操作为什么有问题啊
<br>内容:我的程序代码是:<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;CFile&nbsp;&nbsp;&nbsp;&nbsp;LogFile;<BR>&nbsp;&nbsp;&nbsp;&nbsp;CHAR str[1024];<BR>&nbsp;&nbsp;&nbsp;&nbsp;if(!LogFile.Open(&#34;.\\info.inf&#34;,CFile::modeCreate|CFile::modeReadWrite))<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AfxMessageBox(&#34;打开文件出错&#34;);<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;else<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LogFile.Read(str,LogFile.GetLength());<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_Info.Format(&#34;%s&#34;,str);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LogFile.Close();<BR> <BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>什么地方有问题啊?
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:爱丽思 回复日期:2003-08-27 11:04:48
<br>内容:读数据呀, 只读就行了啊,<BR>str初始化时没有清空
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:cuihp 回复日期:2003-08-27 11:07:58
<br>内容:CHAR str[1024];<BR>LogFile.Read(str,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LogFile.GetLength()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:cuihp 回复日期:2003-08-27 11:24:57
<br>内容:sorry ,我的上一贴有误。<BR><BR>这一行<BR>if(!LogFile.Open(&#34;.\\info.inf&#34;,CFile::modeCreate|CFile::modeReadWrite))<BR>已经把能够打开的文件清空了,所以即使打开,也读不到任何信息。<BR>去掉CFile::modeCreate。可以打开一个存在但没有被独占的文件。<BR><BR>即使这样&nbsp;&nbsp;&nbsp;&nbsp;<BR>LogFile.GetLength() 也许超过了1024,即str的范围。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:lzy59418 回复日期:2003-08-27 11:35:36
<br>内容:我这样改了,好了;谢谢cuihp的指点!<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CFile&nbsp;&nbsp;&nbsp;&nbsp;LogFile;<BR>&nbsp;&nbsp;&nbsp;&nbsp;CHAR str[1024];<BR>&nbsp;&nbsp;&nbsp;&nbsp;if(!LogFile.Open(&#34;.\\info.inf&#34;,CFile::modeRead))<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AfxMessageBox(&#34;打开文件出错&#34;);<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;else<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UINT cnt=LogFile.GetLength();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LogFile.Read(str,cnt);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;str[cnt]='\0';<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_Info.Format(&#34;%s&#34;,str);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LogFile.Close();<BR> <BR>&nbsp;&nbsp;&nbsp;&nbsp;}
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:爱丽思 回复日期:2003-08-27 11:38:48
<br>内容:这几行应该这样写:<BR><BR><BR>cnt = LogFile.Read(str,1024);<BR>if (cnt==1024)<BR>&nbsp;&nbsp; cnt = 1023;<BR>str[cnt] = '\0';<BR><BR><BR>2003-8-27 11:39:16

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -