I wish to read the last line of a .csv file without having to read the entire file (they're quite long). The only way I could think to do it is like this:

int main(int argc, char *argv[])
	ifstream fin("test.csv");
	streamoff offset = -2;
	char ch;

		fin.seekg(offset, ios_base::end);
		fin.read(&ch, 1);
	} while (ch != '\n');

	char szLastLine[128];
	fin.getline(szLastLine, 128);

	cout << szLastLine << endl;

	return 0;
That seems to work fine but I have read that you're not supposed to use seekg with text files so I don't know if this code is good or not.

Is this code okay and if not is there a better solution?

Thanks for any help you can offer.