C ++编译器无法识别std :: stringstream :: swap

时间:2014-06-26 11:33:52

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

我正在尝试使用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等)没有帮助。我错过了什么?

1 个答案:

答案 0 :(得分:7)

从GCC实施状态:

  

部分:27.5
  描述:Iostreams基类
  支持:部分
  的注释

     
      
  • move上缺少swapbasic_ios次操作。
  •   
  • 缺少io_errciostream_category
  •   
  • ios_base::failure不是来自system_error
  •   
  • 缺少ios_base::hexfloat
  •   

更多信息here