C++初始化,之不明白篇 cout<<x<<endl 与 cout<<"x = "<<cout<<x<<endl的输出的值会不一样

代码如下

#include <iostream>
using namespace std;

class point
{
public :
    int x;
    int y;
    point()
    {
        x=0;
        y=0;
    }
    void output()
    {
        cout<<"x =";
        cout<<x<<endl;
        cout<<"y =";
        cout<<y<<endl;
        cout<<"x = "<<cout<<x<<endl;
        cout<<"y = "<<cout<<y<<endl;
    }
};

int main(int argc, char *argv[])
{
    point pt;
    pt.output();
    return 0;
}

 

输入结果:


x = 0
y = 0
x = 0x4453c40
y = 0x4453c40
请按任意键继续. . .

 

cout<<x<<endl输出的数字

cout<<"x = "<<cout<<x<<endl;输出的字符串,已经初始化为0,为何是0x4453c40

疑问为何 cout<<x<<endl 与cout<<"x = "<<cout<<x<<endl的输出会不一样,请高手告之。

编译环境为vs2008 与c-free,

原文地址:https://www.cnblogs.com/ITBread/p/3656015.html