std::stringstream推理在Visual Studio 2013上有效,但在Linux下无效

std::stringstream reasignment works on Visual Studio 2013 but not under Linux

本文关键字:有效 但在 无效 Linux 2013 推理 stringstream Visual Studio std      更新时间:2023-10-16

在Windows上获得完美成功后,我正试图在Linux上编译以下代码:

std::string str = stream.str();
auto decrement = [](char c) { return c - 100; };
std::transform(str.begin(), str.end(), str.begin(), decrement);
stream = std::stringstream(str); // LINE ACCUSING ERROR

我在尝试重新设计std::字符串流时收到的错误是:

158:错误:使用已删除的函数"std::basic_stringstream&std::basic_stringstream::operator=(conststd::basic_stringstream&)'stream=std::字符串流(str);^

std::stringstream不可复制,但只能移动(因为C++11)。我的猜测是,您使用g++4.9或更早版本,即使它支持C++11,它也不能完全支持流的移动语义。g++5,并在以后编译您的代码。

报告的错误可追溯到4.7,在5.x中修复https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54316

相关文章: