The source code is as the following.
cout << '\\' << endl; //OK, output is \
cout << '\\\\' << endl; //OK, output is an integer 23644, but why?
The statement cout << '\\\\' << endl;
invokes the following function of class ostream
.
_Myt& __CLR_OR_THIS_CALL operator<<(int _Val)
I know it is strange to write the expression '\\\\'
, But I don’t understand why it doesn’t fail. How to explain the result?
This may happen because std::cout is writing to output buffer which is waiting to be flushed. If no flushing occurs nothing will print. So you may have to flush the buffer manually by doing the following: std::cout.
The C++ cout statement is the instance of the ostream class. It is used to produce output on the standard output device which is usually the display screen. The data needed to be displayed on the screen is inserted in the standard output stream (cout) using the insertion operator(<<).
The cout object in C++ is an object of class ostream. It is defined in iostream header file. It is used to display the output to the standard output device i.e. monitor. It is associated with the standard C output stream stdout.
Why this C++ code not showing any output? There is not much outputs in this code. You can add some check point outputs (some outputs at strategic points in code to get a print every time execution cross such a point) to get an idea of what your code is doing, or turn to debugger.
This is a multicharacter literal and has type int
.
[lex.ccon]/2:
An ordinary character literal that contains more than one c-char is a multicharacter literal. A multicharacter literal, or an ordinary character literal containing a single c-char not representable in the execution character set, is conditionally-supported, has type int, and has an implementation-defined value.
You should use "\\\\"
, which is char const[3]
: two \ and a NUL byte at the end.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With