4

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?

10
  • 1
    The thing missing might be that it simple isn't in the GCC C++ standard library for GCC 4.8.2. You might want to try GCC 4.9. Commented Jun 26, 2014 at 11:38
  • 3
    Take a look at row 27.8. Doesn't seem to be fixed in GCC 4.9 Commented Jun 26, 2014 at 11:43
  • As compliant as GCC can be, little missing things like this can be just plain irritating. Commented Jun 26, 2014 at 11:46
  • It's not available yet in GCC but it is in clang. Commented Jun 26, 2014 at 11:47
  • 1
    It works from cppreference because clang's standard library, libc++, is used. They implemented C++11 back in 2011 (because, unlike GCC's library, there was nothing to be backwards-compatible with) Commented Jun 26, 2014 at 12:53

1 Answer 1

7

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.