How to print #39;#39; instead of a newline?(如何打印 而不是换行符?)
问题描述
我正在编写一个程序,它使用打印其输入的十六进制转储.但是,当传入换行符、制表符等并破坏我的输出格式时,我遇到了问题.
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.
这篇关于如何打印 ' ' 而不是换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何打印 ' ' 而不是换行符?
基础教程推荐
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- CString 到 char* 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
