C++定位到文件某一行

ifstream & seek_to_line(ifstream & in, int line)
//將打開的文件in,定位到line行。
{
    int i;
    char buf[1024];
    in.seekg(0, ios::beg);  //定位到文件開始。
    for(i = 0; i < line; i ++)
    {
        in.getline(buf, sizeof(buf));//讀取行。
    }
    return in;
}
相關文章
相關標籤/搜索