Getting square instead of new line in output to a file
I'm trying to get an output into a text file. Always when I add to in endl or "\n" it doesn't start a new line, but puts a square in the file instead.
I've done开发者_如何学Python it in Dev-C++ and also with Qt, but always the same result. Do you know where's the problem?
Thanks for your answers.
If you want to display a new line in Windows, use "\r\n"
instead "\n"
.
(read more at http://en.wikipedia.org/wiki/Newline#Representations)
If you open the file in text mode [i.e. if you used ofstream, dont add ios::bin], the program should write the correct newline characters. notepad may be trying to read it in the wrong format. Try using wordpad and confirm that the characters are correct.
Which text editor are you using to view the file? Usually when you see a "square" its a decoding error, and the text editor didn't read the output correctly;
If you are on Windows, try opening the same file with Notepad and Wordpad, see if the "square" persists in both options. If one shows the correct output - it means the other editor simply can't decode the text!
精彩评论