在文件输出中获取正方形而不是换行
我正在尝试将输出放入文本文件中。总是当我添加到 in endl 或“\n”时,它不会开始新行,而是在文件中放置一个正方形。
我已经在 Dev-C++ 和 Qt 中完成了它,但总是相同的结果。你知道问题出在哪里吗?
感谢您的回答。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想在 Windows 中显示新行,请使用
"\r\n"
而不是"\n"
。(了解更多信息,请访问 http://en.wikipedia.org/wiki/Newline#Representations )
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)
如果您以文本模式打开文件[即如果您使用ofstream,则不要添加ios::bin],程序应该写入正确的换行符。记事本可能试图以错误的格式读取它。尝试使用写字板并确认字符是否正确。
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.
您使用哪个文本编辑器来查看该文件?通常,当您看到“正方形”时,它是一个解码错误,并且文本编辑器没有正确读取输出;
如果您使用的是 Windows,请尝试使用记事本和写字板打开同一文件,看看两个选项中是否仍然存在“方块”。如果一个显示正确的输出 - 这意味着另一个编辑器根本无法解码文本!
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!