【问题标题】:Seeking file using c++使用 C++ 查找文件
【发布时间】: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 作为全局变量并仅在缓冲区为空时读取文件.. 它仍然不起作用。

【问题讨论】:

    标签: c++ string file gzip


    【解决方案1】:

    为什么要退出函数并从下一行继续?

    改变你的函数,一个读一行,另一个用它做任何事情

    您可能想在某个地方做某事,或者我错了吗?

    {
    Packets myPacket;
    Test(packet);
    OtherFunction(packet);
    }
    

    【讨论】:

    • 好的 - 那么您可以在哪里进行更改?只是在函数 Test() 中?
    • 尝试调用另一个函数,该函数应该在该行上工作,所以你离开这个范围而没有真正退出函数,当你返回时继续下一行
    • 好吧,我正在调用的函数不是全局的 :)。这就是问题:(
    • 根据您提供的信息,很难说更多。也许您应该显示更多...包括调用您要调用的函数的上下文...
    • 究竟需要什么?
    猜你喜欢
    • 2013-09-03
    • 1970-01-01
    • 2012-06-11
    • 2013-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多