【发布时间】:2014-01-30 10:34:43
【问题描述】:
void Test(Packets& packet)
{
char buf[BUFLEN];
char* offset = buf;
unsigned int foo;
for(;!gzeof(file_handle);){
int len = gzread(file_handle, offset, sizeof(buf)-(offset-buf));
char* cur = buf;
char* end = offset+len;
for (char* eol; (cur<end) && (eol = std::find(cur, end, '\n')) < end; cur = eol + 1)
{
string string_array = string(cur, eol);
if(string_array[0] == 'L'){
packet.foo = blah;
}else{
packet.foo = bar;
}
//After readnig a line.. how do I make sure it quits this function (does another job in some other function) and continous from the next line?
}
#ifdef ROTATION
offset = std::rotate(buf, cur, end);
#else
offset = buf + (end-cur);
std::rotate(buf, cur, end);
#endif
}
std::cout<<std::string(buf, offset) ;
}
读取一行后..如何确保它退出此功能(在其他功能中执行另一项工作)并从下一行继续? 我尝试将 buf、offset 作为全局变量并仅在缓冲区为空时读取文件.. 它仍然不起作用。
【问题讨论】: