Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you output the \ symbol using cout?

Tags:

c++

How do you output \ symbol using cout?

like image 533
SomeUser Avatar asked Oct 30 '09 16:10

SomeUser


2 Answers

Since C++11 you can also use raw string literals.

std::cout << R"(There is no need to escape backslash here \)";

Escape characters (like \n \t or " ) are not processed in the raw string literals.

like image 129
Dharman Avatar answered Sep 18 '22 15:09

Dharman


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 ('?')
like image 24
Tom Avatar answered Sep 18 '22 15:09

Tom