简体   繁体   English

如何使用cout输出\符号?

[英]How do you output the \ symbol using cout?

如何使用cout输出\\符号?

使用两个反斜杠\\\\

In addition to all the correct answers, see this for further escaped characters 除了所有正确答案之外,请参阅此内容以获取更多转义字符

\a  Bell (beep)
\b  Backspace
\f  Formfeed
\n  Newline
\r  Return
\t  Tab
\\  Backslash
\'  Single quote
\"  Double quote
\xdd    Hexadecimal representation
\ddd    Octal representation
\?  Question mark ('?')

The '\\' character is an escape character in C and C++. '\\'字符是C和C ++中的转义字符。 You can output a literal '\\' by escaping it with itself: 您可以通过自身转义输出文字'\\':

   cout << "This is a backslash: \\";

也许

cout << "\\";
std::cout << '\\';
cout << "\\" << endl;

而不是endl你可以:

cout << "\\ \n";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM