0
以下代碼的輸出是什麼?爲什麼此代碼輸出文字「 n」而不是換行符?
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」而不是換行符?
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
。
我們會從你那裏得到很多這些嗎? – 2011-05-05 21:18:17
@unapersson你的意思是? – cong 2011-05-05 21:19:37
因爲\\會輸出一個\。你可以使用'std :: endl'獲得你想要的效果:'std :: cout <<「輸出是什麼」<< std :: endl <<「hello \'world \'world」;' – sitnik 2011-05-05 21:19:53