错误:'std :: cout.std :: basic_ostream中'operator ='不匹配 [英] Error: no match for 'operator=' in 'std::cout.std::basic_ostream

查看:137
本文介绍了错误:'std :: cout.std :: basic_ostream中'operator ='不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出以下代码:

int number = 49;



执行以下语句后输出结果是什么?



Given the following code:
int number = 49;

what will the output be after the following statements are executed?

if(number >= 50)
cout << "yes" << endl;
cout << number = number + 1;





[已添加]

输出什么? 50或是50?

[/ added]



我的尝试:





[added]
What will be the output? 50 or Yes 50?
[/added]

What I have tried:

#include <iostream>
using namespace std;

int main ()

{
    int number = 49;

    if ( number >= 50)
    {
        cout << "Yes " << endl;
        cout << number = number + 1;
    }

}

推荐答案

引用:

cout<< number = number + 1;

cout << number = number + 1;

这个语句错误(正如编译器注意到:-)),因为插入操作符的优先级高于赋值操作符。







以下程序

This statement is wrong (as the compiler noticed :-) ), because the insertion operator has higher precedence than the assignment one.



The following program

#include <iostream>
using namespace std;

int main()
{
  int number = 49;

  if ( number >= 50)
    cout << "Yes " << endl;
  cout << (number = number + 1);
}





仅输出 50


此代码的输出:

The output od this code:
#include <iostream>
using namespace std;
int main ()
{
    int number = 49;
    if ( number >= 50)
    {
        cout << "Yes " << endl;
        cout << (number = number + 1);
    }
}



不算什么,因为我理解这段代码。


is nothing as I understand this code.


这篇关于错误:'std :: cout.std :: basic_ostream中'operator ='不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆