如何打印“\ n”而不是换行符? [英] How to print '\n' instead of a newline?
问题描述
我怎样才能使用printf(或猜测)打印\ n,而不是打印一个实际的换行符?我只需要为此做一些手动解析?
编辑:我正在动态接收我的数据,这不仅仅是我关于,而是所有的符号。例如,这是我的printf语句:
printf(%c,theChar);
当一个换行符作为theChar传入时,如何使这个print \\\
成为可能当Char是一个有效的可打印字符时打印普通文本?
打印\\ - \\ 产生\,然后n被识别为普通符号。有关详情,请参阅此处。
I am writing a program that uses prints a hex dump of its input. However, I'm running into problems when newlines, tabs, etc are passed in and destroying my output formatting.
How can I use printf (or cout I guess) to print '\n' instead of printing an actual newline? Do I just need to do some manual parsing for this?
EDIT: I'm receiving my data dynamically, it's not just the \n that I'm corned about, but rather all symbols. For example, this is my printf statement:
printf("%c", theChar);
How can I make this print \n when a newline is passed in as theChar but still make it print normal text when theChar is a valid printable character?
Print "\\n" – "\\" produces "\" and then "n" is recognized as an ordinary symbol. For more information see here.
这篇关于如何打印“\ n”而不是换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!