I have two files "linuxUTF8.srt" and "macANSI.srt". I am reading these files using getline(). as macANSI.srt has '\r' as line ending I am reading the whole file rather than a single line. I know I have to pass '\r' as delimiter but how do I know what type of line ending character I am dealing with.
We will need to read the block and then find out the appropriate line-ending.
So, we will need to open the file in binary mode and read the last characters.
Read the whole file into a string. Then find the first occurrence in the string of /n or /r using .find(). Then you know which to use. Create an istringstream from the file string and then use getline() on the istringstream with the required delimiter.
The issue you have is if you have a termination of both \n and \r. If you have this, then you'll need to remove one. Choose the one that occurs last. Then remove the other from the end of the obtained string.