简体   繁体   中英

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++. You can output a literal '\\' by escaping it with itself:

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

也许

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

而不是endl你可以:

cout << "\\ \n";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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