c++ - Stringstream编译错误只出现在linux环境下

标签 c++ linux c++11

我在桌面上使用 Visual Studio 用 C++ 编写了一个程序。在该环境下,程序编译和执行没有错误,输出完全符合预期。

但是,当我尝试将我的源代码移动到 linux 系统并编译它时,我遇到了与我使用 stringstream 相关的错误。代码具有以下形式:

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

int main() {
    string line;
    stringstream ssline;
    ssline = stringstream(line); //where the error occurs
}

我在我的程序中多次使用这个赋值操作,就像我说的——当我使用 Visual Studio 编译时我没有造成任何问题。在我的 linux 系统上,gnu 编译器和 intel 编译器都抛出相同的错误,内容如下:

ProgramName.cpp:73:12: error: use of deleted function
‘std::basic_stringstream<char>& std::basic_stringstream<char>::operator=
(const std::basic_stringstream<char>&)’
    ssline = stringstream(line);
                ^
In file included from ProgramName.cpp:13:0:
/usr/include/c++/4.8.2/sstream:502:11: note:
‘std::basic_stringstream<char>& std::basic_stringstream<char>::operator=(const std::basic_stringstream<char>&)’
is implicitly deleted because the default definition would be ill-formed:
    class basic_stringstream : public basic_iostream<_CharT, _Traits>

我不知道这个错误是怎么回事,也不知道为什么它似乎是系统相关的。我可以重写我的源代码以避免使用 stringstream,但我不想这样做。因为我知道它适用于我的桌面环境。

我很感激能为解决这个困难提供的任何帮助。 提前致谢。

最佳答案

It seems自 GCC 5 以来,GCC 已为 std::stringstream 移动赋值,而您使用的是 GCC 4.8.2。

您的 GCC 太旧,需要升级。

关于c++ - Stringstream编译错误只出现在linux环境下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51562264/

相关文章:

c++ - 为什么内置排序无法对 vector 映射进行排序?

c++ - C++类中的矩阵

c++ - 转换构造函数 : How do you explain a function given different arguments in c++

linux - Makefile 在 foreach 循环中使用 ifeq 条件

c++代码无法编译并出现奇怪的错误

c++ - 重载时区分函数

c++ - boost::container::vector 和 std::vector 有什么区别

linux - PCIE linux 内核驱动程序中的流式 DMA

linux - 如何使用ftw删除目录内容

c++ - 按属性对包含对象的列表进行排序