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

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

问题描述

我正在编写一个程序,它使用打印其输入的十六进制转储.但是,当传入换行符、制表符等并破坏我的输出格式时,我遇到了问题.

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.

如何使用 printf(或我猜是 cout)打印 ' ' 而不是打印实际的换行符?我只需要为此做一些手动解析吗?

How can I use printf (or cout I guess) to print ' ' instead of printing an actual newline? Do I just need to do some manual parsing for this?

我正在动态接收我的数据,这不仅仅是我讨厌的 ,而是所有符号.例如,这是我的 printf 语句:

I'm receiving my data dynamically, it's not just the that I'm corned about, but rather all symbols. For example, this is my printf statement:

printf("%c", theChar);

当换行符作为 theChar 传入时,如何打印 但当 theChar 是有效的可打印字符时,它仍然打印普通文本?

How can I make this print when a newline is passed in as theChar but still make it print normal text when theChar is a valid printable character?

推荐答案

打印\n"——\"产生",然后n"被识别为普通符号.如需更多信息,请参阅此处.

Print "\n" – "\" produces "" and then "n" is recognized as an ordinary symbol. For more information see here.

这篇关于如何打印 ' ' 而不是换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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