Rather than seeking back to the beginning and reading the first line twice, I think I'd approach things with something like:
std::ifstream file("filename");
std::string line;
std::getline(file, line);
process(line);
do {
process(line);
} while (getline(file, line));
At the moment, this assumes that process
doesn't modify line
(but if needed, it's easy enough to make an extra copy of it for the first call).
Edit: given the modified requirements in the edited answer, it sounds like the seek is really needed. That being the case, it's probably cleanest to clear
the stream before proceeding:
std::getline(file, line);
process1(line);
file.seekg(0);
file.clear();
process2(file);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…