This looks like a similar question to this one, however I think my case might actually be a bit different. The code is as below:
void readOmronResults(string fil
If they are Mac OS endings '\r'
, according to the docs: http://www.cplusplus.com/reference/string/string/getline/ this behaviour is not surprising.
Paraphrasing the docs: when not giving a delimiter, getline
will ready until a newline ('\n'
) character is encountered.
My operating system is Windows and according to my text editor the original input file is Mac-OS style.
Yes, this is the problem. Windows' C and C++ standard libraries will assume that text files use the Windows line ending, U+0D U+0A
.
"Mac OS style" is an odd thing for the text editor to say, because the other line ending in common use U+0A
which is common to the entire Unix family including Linux. Long ago, Mac OS used U+0D
which makes the phrase "Mac OS style" ambiguous and anachronistic.
But if it is because of this, why is the original code (with the two lines commented out) able to give a correct result?
It didn't. Both versions of the program treat the file as if it contains one very long line.