If you don't move your files between Windows/Linux, you should be fine.
However, in many circumstances, you have to read both conventions from both compiled programs. This is common with all sorts of documents and some network protocols. If this is the case, I recommend the following procedure:
- Scan for
\r
or \n
.
- If char found is
\r
, then also look for \n
immediately after it. If it exists, then consume it as part of the same newline.
This scanning procedure will accept files with CR
, LF
, and CR+LF
line endings. It is analogous to what many encoding-detecting higher level string streams do.
Here is another answer which outlines this procedure in code for istream
:
Getting std :: ifstream to handle LF, CR, and CRLF?