使用cout输出cerr

mir*_*o_x 8 c++ iostream compiler-errors

我遇到了一段基本上如下的代码:

#include <iostream>

using namespace std;
int main()
{
    cout << cerr << " Hi.";

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出:

0x601088 Hi.
Run Code Online (Sandbox Code Playgroud)

首先,为什么有人会'cout << cerr'它没有意义.第二,上面的输出是什么意思?

值得一提的是,在我的机器上,上面的代码编译并执行没有错误.

但是,在运行相同版本的gcc 5.4.0的不同机器(服务器ssh连接)上执行更复杂的代码(执行与上述相同的操作)会在执行make时产生此错误(为了清晰起见缩短):

error: no match for ‘operator<<’ (operand types are ‘std::ostream {aka std::basic_ostream<char>}’ and ‘std::ostream {aka std::basic_ostream<char>}’)
     cout << cerr << "DB: Field " + e.table + "[" + e.index + "]." + e.field
Run Code Online (Sandbox Code Playgroud)

有什么想法吗?

Fra*_*eux 13

直到c ++ 11,才std::basic_ios提供隐式转换void*.此代码不能使用c ++ 11或更高版本进行编译.你基本上有这个,它与旧版本的gcc编译:

#include <iostream>
int main()
{
    void * x = std::cerr;
    std::cout << x << " Hi.";

    return 0;
}
Run Code Online (Sandbox Code Playgroud)