[英]Why does this code output a literal “\n” instead of a newline?
以下代码的输出是什么?
std::cout<<"what is the output \\n hello \'world\' world";
我认为输出应为:
what is the output
hello 'world' world
但是实际输出是the output \\n hello 'world' world
为什么不将\\n
输出为新行?
您的双反斜杠\\\\
是产生\\
的转义符,因此您看到\\n
。 如果要换行,请使用单个反斜杠\\n
。
\\n
指定换行符。 但是,如果您想要一个反斜杠字符,会发生什么? 为此,C ++允许您使用\\\\
。 第一个反斜杠转义第二个反斜杠,从而得到一个反斜杠,并且没有特殊的转换。
这就是这里的内容,然后是n
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.