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);
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);
相关阅读 更多 +