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

📄 subject_30201.htm

📁 一些关于vc的问答
💻 HTM
字号:
<p>
序号:30201 发表者:sos 发表日期:2003-02-21 08:53:07
<br>主题:(TXT格式)大文件怎样分批读出,请大虾指点,谢了
<br>内容:(TXT格式)大文件怎样分批读出,请大虾指点,谢了
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:bird 回复日期:2003-02-21 08:57:32
<br>内容:http://www.vchelp.net/vchelp/archive.asp?type_id=26&amp;class_id=1&amp;cata_id=2&amp;article_id=245<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>
回复者:sos 回复日期:2003-02-21 09:10:30
<br>内容:如果我用SDK,不用MFC,代码应该怎么写呢,谢谢
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:upstream 回复日期:2003-02-21 09:15:00
<br>内容:你的文本文件的格式是什么样子的<BR>用标准c++的ftream等文件输入输出流也可以实现<BR>这个和采用sdk或者mfc无关。<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>
回复者:sos 回复日期:2003-02-21 09:21:33
<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>
<font color=red>答案被接受</font><br>回复者:活下去,像牲口一样活下去 回复日期:2003-02-21 09:36:36
<br>内容:假设test.txt的内容是:<BR>I'm sitting here in a boring room<BR>It's just another rainy Sunday afternoon<BR>I'm wasting my time, I got nothing to do<BR>I'm hanging around, I'm waiting for you<BR>But nothing ever happens -- and I wonder<BR>I'm driving around in my car<BR>I'm driving too fast, I'm driving too far<BR>I'd like to change my point of view<BR>I feel so lonely, I'm waiting for you<BR>But nothing ever happens, and I wonder<BR>I wonder how, I wonder why<BR>Yesterday you told me 'bout the blue blue sky<BR>And all that I can see is just a yellow lemon tree<BR>I'm turning my head up and down<BR><BR>读文件的操作<BR><BR>#include "fstream.h"<BR>#define MaxBuffer 256<BR><BR>char lpBuffer[MaxBuffer];<BR>fstream readfile("test.txt",ios::in);<BR>while(!readfile.eof())<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;readfile.getline(lpBuffer,sizeof(lpBuffer),'\n');//每次读入一行<BR>&nbsp;&nbsp;&nbsp;&nbsp;//其他的操作,比如对字符进行处理&nbsp;&nbsp;&nbsp;&nbsp;<BR>}<BR>fstream.close(); <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>
回复者:bb 回复日期:2003-02-21 10:11:22
<br>内容:如果是四五百兆的文件带缓冲的i/o根本打不开文件。<BR>要用文件直接读写操作。<BR>不用MFC的CFile,则直接用open或WINAPI CreateFile以二进制方式打开文件。<BR><BR>例:<BR>#define BUF_SIZE 64*1024<BR>&nbsp;&nbsp;char buf[BUF_SZIE]; //64k 读缓冲<BR>&nbsp;&nbsp;int fd=open("abc.txt", _O_BINARY|_O_RDONLY);<BR>&nbsp;&nbsp;size=BUFSIZE;<BR>&nbsp;&nbsp;char *bufPos=buf;<BR>&nbsp;&nbsp;while(!eof(fd))<BR> {<BR>&nbsp;&nbsp;&nbsp;&nbsp; size=read(fd,buf,size );<BR>&nbsp;&nbsp;&nbsp;&nbsp; if(size&lt;0)<BR>&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; error!<BR>&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp; //do somthing with this 64k data<BR>&nbsp;&nbsp;&nbsp;&nbsp; ....<BR>&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;//如果要分行处理,假设一行不超过64k字节&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;char *lineBegin=buf;<BR>&nbsp;&nbsp;&nbsp;&nbsp;char lineBuf[BUF_SIZE];<BR>&nbsp;&nbsp;&nbsp;&nbsp;char *pos=strchr(buf, '\n');<BR>&nbsp;&nbsp;&nbsp;&nbsp;while(pos)&nbsp;&nbsp;//处理buf中的所有行<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memcpy(lineBuf, lineBegin, pos-lineBegin);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lineBuf[pos-lineBegin]=0;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//process line data in lineBuf<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ....<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lineBegin=pos+1;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pos=strchr(buf,'\n');<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;memmove(buf, lineBegin,BUF_SIZE-lineBegin);//将剩余的数据移到buf前端<BR>&nbsp;&nbsp;&nbsp;&nbsp;bufPos=buf+BUF_SIZE-lineBegin;<BR>&nbsp;&nbsp;&nbsp;&nbsp;size=BUF_SIZE+BUF_SIZE-lineBegin;<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; <BR><BR>&nbsp;&nbsp; <BR>&nbsp;&nbsp;
<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 + -