Avoid \r\n while reading text from a binary file
<p>I have a binary file packing lots of files (something like a .tar), where I can found both binary and text files.</p>

<p>When processing in memory strings, carriage lines are usually <strong>'\n'</strong>, but if I read the text part from this packed file, I get <strong>"\r\n"</strong>. Therefore processing this text gives me errors.</p>

<p>Here is the code for reading the text from a binary file:</p>

<pre><code>FILE* _fileDescriptor;                        // it's always open to improve performance
fopen_s(&amp;_fileDescriptor, _filePath.string().c_str(), "rb"); 

char* data = new char[size + 1];              // size is a known and correct value
fseek(_fileDescriptor, begin, SEEK_SET);      // begin is another known value, where the file starts inside the packed one
fread(data, sizeof(char), size, _fileDescriptor);
data[it-&gt;second.size] = '\0';
</code></pre>

<p>This gives me the right text into <strong>data</strong>, but the following code gives me error when reading an empty line:</p>

<pre><code>istringstream ss(data);      // create a stringstream to process it in another function
delete[] data;               // free the data buffer

// start processing the file
string line;
getline(infile, line);       // read an empty line

if(line.size() &gt; 0) {
    /*
     enters here, because the "empty" line was "\r\n", and now the value of line is '\r', therefore line.size() == 1
    */
    ...
</code></pre>

<p>So, any advice to avoid the '\r'?</p>

<p>I edited it on Notepad++. Changing its configuration to use '\n' instead of '\r\n' as line carriage works, but I don't want to depend on this because other people can miss that, and it would be very hard to spot the problem if that happens.</p>
