📄 subject_30201.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&class_id=1&cata_id=2&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> readfile.getline(lpBuffer,sizeof(lpBuffer),'\n');//每次读入一行<BR> //其他的操作,比如对字符进行处理 <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> char buf[BUF_SZIE]; //64k 读缓冲<BR> int fd=open("abc.txt", _O_BINARY|_O_RDONLY);<BR> size=BUFSIZE;<BR> char *bufPos=buf;<BR> while(!eof(fd))<BR> {<BR> size=read(fd,buf,size );<BR> if(size<0)<BR> {<BR> error!<BR> }<BR> //do somthing with this 64k data<BR> ....<BR> <BR> //如果要分行处理,假设一行不超过64k字节 <BR> char *lineBegin=buf;<BR> char lineBuf[BUF_SIZE];<BR> char *pos=strchr(buf, '\n');<BR> while(pos) //处理buf中的所有行<BR> {<BR> memcpy(lineBuf, lineBegin, pos-lineBegin);<BR> lineBuf[pos-lineBegin]=0;<BR> //process line data in lineBuf<BR> ....<BR> lineBegin=pos+1;<BR> pos=strchr(buf,'\n');<BR> }<BR> memmove(buf, lineBegin,BUF_SIZE-lineBegin);//将剩余的数据移到buf前端<BR> bufPos=buf+BUF_SIZE-lineBegin;<BR> size=BUF_SIZE+BUF_SIZE-lineBegin;<BR> }<BR> <BR><BR> <BR><BR> <BR>
<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 + -