How do you output the \ symbol using cout?

前端 未结 7 773
误落风尘
误落风尘 2020-12-10 05:32

How do you output \\ symbol using cout?

相关标签:
7条回答
  • 2020-12-10 06:13

    Maybe

    cout << "\\";
    
    0 讨论(0)
  • 2020-12-10 06:15

    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: \\";
    
    0 讨论(0)
  • 2020-12-10 06:19
    std::cout << '\\';
    
    0 讨论(0)
  • 2020-12-10 06:19
    cout << "\\" << endl;
    

    Instead of endl you could:

    cout << "\\ \n";
    
    0 讨论(0)
  • 2020-12-10 06:21

    Use two backslashes \\

    0 讨论(0)
  • 2020-12-10 06:23

    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
    \ffffd    Octal representation
    \?  Question mark ('?')
    
    0 讨论(0)
提交回复
热议问题