具有“cout” myint“。为什么它工作? [英] Typo with "cout < myint". Why does it work?
本文介绍了具有“cout” myint“。为什么它工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个代码,我搜索小时为什么它不能打印我的收入
I have this code and I searched for hours why it fails to print my income
int const income = 0;
std::cout << "I'm sorry, your income is: " < income;
直到我发现我错过写<<
但写了<
。为什么编译器没有检测到这个错误?我不知道为什么比较 cout
有意义?
Until I found I missed to write <<
but wrote <
. Why doesn't the compiler detect this and error out? I'm not sure why comparing cout
makes sense?
推荐答案
常量0也是一个空指针常量 - 它可以与 ostream
'运算符void *
的结果进行比较。请注意,如果常数的值为0,则它将失败。
integral constant 0 is also a null pointer constant - it can be compared to the result of ostream
's operator void *
. Note that it'll fail if the constant has any value but 0.
这篇关于具有“cout” myint“。为什么它工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文