小编ol2*_*020的帖子

C++编译器命令顺序不一致

我尝试运行一个简单的 C++ 程序,但我不确定为什么不同的编译器提供不同的输出

#include <iostream>

struct A
{
    A() { std::cout << "Object A created" << std::endl; }

    friend std::ostream& operator<<(std::ostream& os, const A& a)
    {
        os << a.str << "\n";
        return os;
    }

    static bool printMe()
    {
        std::cout << "static bool printMe() of object A" << std::endl;
        return true;
    }
    std::string str{"This is object A"};
};


int main()
{
    std::cout << A() << (A::printMe() ? "TRUE" : "FALSE") << std::endl;
}
Run Code Online (Sandbox Code Playgroud)

OUTPUT1:一些编译器提供以下输出:

Object A created
This is object A …
Run Code Online (Sandbox Code Playgroud)

c++

3
推荐指数
1
解决办法
122
查看次数

标签 统计

c++ ×1