C++ compiler does not recognize std::stringstream::swap

前提是你 提交于 2019-12-01 21:39:10

问题


I am trying to compile the following code with 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);
}

I get the following error:

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

According to this reference it should work. Using different -std flags (gnu++11, c++0x etc.) didn't help. What am I missing?


回答1:


From the GCC implementation status:

Section: 27.5
Description: Iostreams base classes
Support: Partial
Comments:

  • Missing move and swap operations on basic_ios.
  • Missing io_errc and iostream_category.
  • ios_base::failure is not derived from system_error.
  • Missing ios_base::hexfloat.

more info here



来源:https://stackoverflow.com/questions/24429441/c-compiler-does-not-recognize-stdstringstreamswap

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!