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

📄 subject_28380.htm

📁 vc
💻 HTM
字号:
<p>
序号:28380 发表者:白痴 发表日期:2003-01-21 02:08:22
<br>主题:FILE的操作问题???
<br>内容:文件描述:<BR>{ssdss},{dfdfd},{asdasda},……………………<BR>有多个{}组成,我想把每个{}中的内容读出来,就是ssdss,dfdfd,asdasda,………………<BR>我该怎么做??
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:upstream 回复日期:2003-01-21 08:00:23
<br>内容:{},{}之间是否有逗号,?假设有这个逗号.<BR><BR>利用CFile类读文件.因为我不知道对于这个类,如何判断一个文件是否结束,所以只好一下把所有字符读入到一个字符数组,然后对这个数组进行分析.<BR><BR>CStringList StringList;<BR>CString strTemp;<BR>strTemp.Empty();<BR>CFile myFile;<BR>myFile.Open("文件名",CFile::modeRead|CFile::modeCreate|CFile::modeNoTruncate);<BR>int nLen=myFile.GetLength();<BR>char *pBuffer;<BR>pBuffer=new char[nLen];<BR>myFile.Read(pBuffer,nLen);<BR>for(int i=0;i&lt;nLen;i++)<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;if(pBuffer[i]=='{'||pBuffer[i]==',')<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;continue;<BR>&nbsp;&nbsp;&nbsp;&nbsp;else if(pBuffer[i]=='}')<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;StringList.AddTail(strTemp);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strTemp.Empty();<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strTemp+=pBuffer[i];<BR>}<BR>myFile.Close();<BR>delete []pBuffer;<BR><BR><BR><BR>最后结果读入到CStringList中,要取出其中的各个子串,利用下面的办法。<BR>CString strText;<BR>POSITION pos;<BR>pos=StringList.GetHeadPosition();<BR>while(pos!=NULL)<BR>{<BR>&nbsp;&nbsp; strText=StringList.GetAt(pos);<BR>&nbsp;&nbsp; //AfxMessageBox(strText);//调试<BR>&nbsp;&nbsp; StringList.GetNext(pos );<BR>}<BR>
<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-01-21 09:46:20
<br>内容:谢谢,upstream<BR>没有逗号<BR>如果我知道文件的结束的标志是※<BR>怎么办?(我不想一次读入那么多的内容)<BR>特别是{}分开了,不在一次读入的内容中。<BR>2003-1-21 9:51:39

⌨️ 快捷键说明

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