C++ 错误:无法将'std::basic_ostream'左值绑定到'std::basic_ostream&&'sl

C++ 错误:无法将'std::basic_ostream'左值绑定到'std::basic_ostream&&'sl,c++,stringstream,ostream,C++,Stringstream,Ostream,我的朋友给我发了一个代码,他说在Windows中编译成功了。我在linux上尝试过,但失败了,给出了下面的错误。下面是该代码的最小可验证示例 #include <iostream> #include <sstream> using namespace std; int main() { std::stringstream ss, sl; sl << ss; } 但它给 error: cannot bind ‘std::basic_ostream

我的朋友给我发了一个代码,他说在Windows中编译成功了。我在linux上尝试过,但失败了,给出了下面的错误。下面是该代码的最小可验证示例

#include <iostream>
#include <sstream>
using namespace std;

int main()
{
   std::stringstream ss, sl;
   sl << ss;
}
但它给

error: cannot bind ‘std::basic_ostream’ lvalue to ‘std::basic_ostream&&’
    sl << ss;

为什么它在Windows中工作,而不是在Linux中,为什么会发生这种错误?

< P>因为C++ 11,这个代码编译失败,因为操作符

没有匹配的过载。因为C++ 11没有编译这个代码,因为操作符与VisualC++都没有匹配的过载。这段代码,就像你现在展示的一样,不应该在任何地方都能工作。如果你真的想这样做,这里有一个老问题可能会有所帮助。如果它真的能为你的朋友工作,那将是因为编译器有不同版本的STL,而且编译器接受这种语法。你能找出他们在Windows上使用的编译器吗?用Visual C++实现。这段代码,就像你现在展示的一样,不应该在任何地方都能工作。如果你真的想这样做,这里有一个老问题可能会有所帮助。如果它真的能为你的朋友工作,那将是因为编译器有不同版本的STL,而且编译器接受这种语法。你能找出他们在Windows上使用的编译器吗?谢谢。事实上,我现在回想起来,它说在许多蓝线中,但红线表示不能将'std::basic_ostream'左值绑定到'std::basic_ostream&'。蓝线是受支持的运算符。但是红色的错误并不清楚,因为没有操作员,所以发生了错误。谢谢。事实上,我现在回想起来,它说在许多蓝线中,但红线表示不能将'std::basic_ostream'左值绑定到'std::basic_ostream&'。蓝线是受支持的运算符。但红色错误并不清楚是因为没有操作员而发生了错误。

basic_ostream& operator<<( const void* value );