Tom83B
Tom83B

Reputation: 2109

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 it in Dev-C++ and also with Qt, but always the same result. Do you know where's the problem?

Thanks for your answers.

Upvotes: 1

Views: 1455

Answers (3)

Foo Bah
Foo Bah

Reputation: 26271

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.

Upvotes: 1

Kaa
Kaa

Reputation: 705

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!

Upvotes: 0

Fábio Perez
Fábio Perez

Reputation: 26088

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)

Upvotes: 1

Related Questions