tags:

views:

212

answers:

5

How do you output \ symbol using cout?

+12  A: 

Use two backslashes \\

Daniel A. White
+3  A: 

Maybe

cout << "\\";
Kinopiko
+3  A: 
std::cout << '\\';
sbi
+15  A: 

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: \\";
mch
+12  A: 

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 ('?')
Tom
There's also correct answers _below_ yours. `:)`
sbi
You missed a few. Also what happens with '\m' (ie a non special character).
Martin York
@Sbi: Right :) 15
Tom