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作为全局变量进行偏移,并仅在缓冲区为空时读取文件..它仍然不起作用。
答案 0 :(得分:1)
为什么要退出该功能并从下一行继续?
改变你的功能,就像读一行一样,另一行做任何事情
在某个地方,你可能想做一些像我这样的错误?{
Packets myPacket;
Test(packet);
OtherFunction(packet);
}