How does the code below work ? where is the counter for the for-loop and how can i reset the counter to line number 0.
for (std::string line;std::getline(ifs, line); )
{
}
Your for loop is equivalent to:
{
std::string line;
while (std::getline(ifs, line)) {
}
}
In other words: "keep iterating as long as getline returns true".
seek. Just one system call instead of two, plus close/re-open introduces a race condition, and while errors related to that may be rare they will be effectively impossible to debug. For instance, on unix-like systems the file may have been deleted from the command line in the mean time and close and re-open will fail (because the file will be gone), while seeking will still work.