The << operator has higher priority than < , so it is parsed as
(cout << a) < " ";
You are not really comparing a string to an integer. Instead, you compare the return value of ostream::operator<< , which is std::cout , to a string literal. This is not legal (in the sense that it has an unspecified result, and it does not make sense), clang warns:
warning: result of comparison against a string literal is unspecified
The reason for compiling is that before C ++ 11, std::ostream can be implicitly converted to void * . In addition, a string literal of type const char[2] splits into a pointer of type const char * . Thus, the < operator now accepts two pointers, which is allowed, although its result is not specified, since the two pointers do not point to the same object.
user529758
source share