简体   繁体   English

错误:无法将 'std::basic_ostream' 左值绑定到 'std::basic_ostream&&' sl << ss;

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

My friend sent me a code where he says sucessfuly compiled in Windows.我的朋友给我发了一个代码,他说在 Windows 中成功编译。 I tried on linux and it failed giving the error below.我在 linux 上进行了尝试,但未能给出以下错误。 Below is a minimum verifiable example of the code.下面是代码的最小可验证示例。

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

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

but it gives但它给了

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

Why it works in windows but not in linux, and why this error happens?为什么它在 windows 中有效,但在 linux 中无效,为什么会发生此错误?

Since C++11 this code fails to compile because there is no matching overload for operator<< with both operands of type std::stringstream .自 C++11 以来,此代码无法编译,因为operator<<没有匹配的重载与std::stringstream类型的两个操作数。

However, prior to C++11, std::ostream provided implicit conversion to void * , so the following overload could be called:但是,在 C++11 之前, std::ostream提供了void *的隐式转换,因此可以调用以下重载:

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

The output would be the same as outputting a null pointer if the stream has an error, otherwise some unspecified non-null pointer value.如果 stream 有错误,则 output 将与输出 null 指针相同,否则一些未指定的非空指针值。

Probably your friend used an old compiler, or a compiler running in old compatibility mode.可能您的朋友使用了旧的编译器,或者以旧的兼容模式运行的编译器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:无法绑定&#39;std :: basic_ostream <char> &#39;左右&#39;std :: basic_ostream <char> &amp;&amp;” - error: cannot bind ‘std::basic_ostream<char>’ lvalue to ‘std::basic_ostream<char>&&’ 无法绑定&#39;std :: ostream {aka std :: basic_ostream <char> }&#39;左值成&#39;std :: basic_ostream <char> &amp;&amp;” - cannot bind 'std::ostream {aka std::basic_ostream<char>}' lvalue to 'std::basic_ostream<char>&&' 错误:无法绑定&#39;std :: ostream {aka std :: basic_ostream <char> }&#39;左值成&#39;std :: basic_ostream <char> &amp;&amp;&#39; - error: cannot bind ‘std::ostream {aka std::basic_ostream<char>}’ lvalue to ‘std::basic_ostream<char>&&’ 重载运算符&lt;&lt;:无法绑定&#39;std :: basic_ostream <char> &#39;左值到&#39;std :: basic_ostream <char> &amp;&amp;&#39; - Overloading operator<<: cannot bind ‘std::basic_ostream<char>’ lvalue to ‘std::basic_ostream<char>&&’ std :: vector:无法绑定&#39;std :: ostream {aka std :: basic_ostream <char> &#39;&#39;左右&#39;到&#39;std :: basic_ostream <char> &amp;&amp;” - std::vector : cannot bind 'std::ostream {aka std::basic_ostream<char>}' lvalue to 'std::basic_ostream<char>&&' 重载operator <<:无法将左值绑定到'std :: basic_ostream <char> &&' - Overloading operator<<: cannot bind lvalue to ‘std::basic_ostream<char>&&’ high_resolution_clock错误:无法绑定&#39;std :: ostream {aka std :: basic_ostream <char> }&#39;左值成&#39;std :: basic_ostream <char> &amp;&amp;&#39; - high_resolution_clock error: cannot bind ‘std::ostream {aka std::basic_ostream<char>}’ lvalue to ‘std::basic_ostream<char>&&’ 错误:无法绑定&#39;std :: ostream {aka std :: basic_ostream <char> } - Error: cannot bind 'std::ostream {aka std::basic_ostream<char>} boost :: PO并且不能绑定到&#39;std :: basic_ostream <char> &amp;&amp;” - boost::PO and cannot bind to ‘std::basic_ostream<char>&&’ std :: basic_ostream与参数 - std::basic_ostream with parameter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM