I have a question regarding what to do with "\n" or "\r\n" etc. when reading a text file in C++. The problem exists when I do the following sequence of operations:
int k; f>>k; string line; getline(f,line); for an input file with something like
1 abc I have to put a f.get() in order to read off the ending "\n" after f>>k. I even have to do f.get() twice if I have "\r\n".
What is an elegant way of reading file like this if I mix >> with getline?
Thank you.
Edit Also, I wonder if there is any convenient way to automatically detect the given file has an end-of-line char "\n" or "\r\n".