The easiest solution would be to load the file into memory and manipulate it from there:
std::vector<std::string> lines;
std::string line;
while(std::getline(file,line)
{
lines.push_back(line);
}
If the file is way to large.
Then you need to build an index of the file that tells you exactly where each line starts.
std::vector<std::streampos> index;
index.push_back(file.tellg());
std::string line;
while(std::getline(file,line)
{
index.push_back(file.tellg());
}
file.setg(0);
file.clear(); // Resets the EOF flag.
Once you have your index. You can jump around the file and read any particular line.
int jumpTo = 50;
file.seekg(index[jumpTo]); // Jump to line 50.
//
// Read 50 lines. Do not read past the end
// This will set the EOF flag and future reads will fail.
for(int loop=0;loop < 50 && ((jumpTo + loop) < index.size());++loop)
{
std::string line;
std::getline(file,line);
}