c++ - Unwanted Carriage Returns in ofstream -


this question has answer here:

the following c++ code:

ofstream out("file.txt"); const char *str = "0\r\n1\r\n2\r\n"; out << str; 

creates following file (file.txt above):

file.txt content

why there cr's , lf's? platform windows 7 , compiler vs 2013.

the situation above cause problem of program parse file line line , program assumes every line contain data. remove empty lines want understand why when str saved, there cr's , lf's.

\n outputs platform-specific newline, in case each \n written \r\n. not need manually add own \r, source of duplication.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -