What is the output of this following code?
std::cout<<"what is the output \\n hello \'world\' world";
I think the output should be:
what is the output
hello 'worl开发者_开发知识库d' world
But the actual output is the output \n hello 'world' world
Why isn't \n
output as a new line?
Your double backslash \\
is an escape that produces \
so you see \n
. If you want a newline, use a single backslash \n
.
\n
specifies a new line character. But what happens if you want a backslash character? For this, C++ allows you to use \\
. The first backslash escapes the second resulting in a single backslash and no special translation.
That's what you have here, followed by n
.
精彩评论