-->

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

2019-02-24 00:42发布

问题:

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



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