12345678910111213141516
void findlastline(ifstream& file, string& lastline) { while(file >> lastline) { getline(file, lastline); if (lastline.length() == 0) { while(!file.eof()) getline(file, lastline); } else getline(file, lastline); } return; }
123456789101112
void findlastline(ifstream& file, string& lastline) { std::string prev, current; while (getline(file, current)) { if (!current.empty()) prev = current; } lastline = current.empty() ? prev : current; }