如何打印“\ n”而不是换行符? [英] How to print '\n' instead of a newline?

查看:413
本文介绍了如何打印“\ n”而不是换行符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个程序,使用它的输入打印一个十六进制转储。然而,我遇到了新行,标签等传入和销毁我的输出格式的问题。



我怎样才能使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆