Typo with “cout < myint”. Why does it work?

后端 未结 4 1643
Happy的楠姐
Happy的楠姐 2020-12-28 14:41

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: \" < inco         


        
4条回答
  •  离开以前
    2020-12-28 15:32

    It does compile with g++ 4.4.3

    #include  
    
    int main (void)
    {
       int const income = 0;
       std::cout << "I'm sorry, your income is: " < income;
    }
    

    However, when running it with -Wall (good practice!), I got a funny message:

    :~/stack$ g++ test.cpp -o temp
    :~/stack$ g++ -Wall test.cpp -o temp
    test.cpp: In function 'int main()':
    test.cpp:5: warning: right-hand operand of comma has no effect
    

    No clue what it actually does (or tries to do)...

提交回复
热议问题