【问题标题】:C++ compiler does not recognize std::stringstream::swapC++ 编译器无法识别 std::stringstream::swap
【发布时间】:2014-08-17 05:49:17
【问题描述】:

我正在尝试使用 g++ (GCC) 4.8.2 20131212 (Red Hat 4.8.2-7) 编译以下代码:

#include <sstream>
using namespace std;

int main(int argc, char ** argv)
{
    auto x = 1;
    stringstream s1, s2;
    s1.swap(s2);
}

我收到以下错误:

g++ -g -std=c++0x -c main.cpp
main.cpp: In function ‘int main(int, char**)’:
main.cpp:8:5: error: ‘std::stringstream’ has no member named ‘swap’
  s1.swap(s2);
     ^
make: *** [main.o] Error 1

根据this reference 它应该可以工作。使用不同的 -std 标志(gnu++11、c++0x 等)没有帮助。我错过了什么?

【问题讨论】:

  • 缺少的可能是它不在 GCC 4.8.2 的 GCC C++ 标准库中。您可能想尝试 GCC 4.9。
  • 看看行27.8GCC 4.9中似乎没有修复
  • 尽可能地符合 GCC 标准,但缺少这样的小东西可能会很烦人。
  • 在 GCC 中尚不可用,但在 clang 中。
  • 它使用 cppreference 工作,因为使用了 clang 的标准库 libc++。他们早在 2011 年就实现了 C++11(因为与 GCC 的库不同,没有什么可以向后兼容)

标签: c++ c++11 g++4.8


【解决方案1】:

从 GCC 实施情况来看:

部分:27.5
说明:Iostreams 基类
支持:部分
评论强>:

  • basic_ios 上缺少moveswap 操作。
  • 缺少io_errciostream_category
  • ios_base::failure 不是从 system_error 派生的。
  • 缺少ios_base::hexfloat

更多信息here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-09
    相关资源
    最近更新 更多