文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>read 读不定长文件

read 读不定长文件

时间:2010-08-26  来源:snailshen

#define READBUFFSIZE 8192
AIX线程堆栈大小为98304字节,所以线程里一次读取的字节数为8192*5.避免线程堆栈太小
int iFd = open(sSouFile.c_str(),O_RDONLY);
        if(iFd == -1){
                cout<<"open file:"<<sSouFile<<" error!!!"<<endl;
                return;
        }
        int pos,pos2;
        string sLastData,sOneData;
        while(read(iFd,buf,READBUFFSIZE*5)>0){
                if(sLastData.size()>0)
                        sOneData = sLastData + string(buf);
                else
                        sOneData = buf;
                memset(buf,0,sizeof(buf));
                pos = pos2 = 0 ;
                sLastData = "";
                while((pos=sOneData.find("\n", pos))!= string::npos){
                        ++i;
                        if(i<=6){
                                pos2 = ++pos;
                                continue;//计费去掉前6行详单头信息
                        }
               
                  //一条纪录
                cout<<"jf rec="<<sOneData.substr(pos2,pos-pos2)<<endl;
                
                  pos2 = ++pos;
                }
                int recsize = sOneData.size();
                if(pos2<recsize)
                        sLastData = sOneData.substr(pos2,recsize-pos2);
               
        }
        close(iFd);
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载