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?

rioki
  • 5,988
  • 5
  • 32
  • 55
peti
  • 55
  • 4
  • 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. – Some programmer dude Jun 26 '14 at 11:38
  • 3
    Take a look at row [27.8](https://gcc.gnu.org/onlinedocs/gcc-4.8.2/libstdc++/manual/manual/status.html#status.iso.2011). Doesn't seem to be fixed in [GCC 4.9](https://gcc.gnu.org/onlinedocs/gcc-4.9.0/libstdc++/manual/manual/status.html#status.iso.2011) – Unda Jun 26 '14 at 11:43
  • As compliant as GCC can be, little missing things like this can be just plain irritating. – Niall Jun 26 '14 at 11:46
  • It's not available yet in GCC but it is in clang. – David G Jun 26 '14 at 11:47
  • Sounds like a job for clang! Like GCC only faster and with clearer error messages! –  Jun 26 '14 at 11:49
  • @0x499602D2 In which version of Clang? Because in v3.4 it doesn't or messing something up http://coliru.stacked-crooked.com/a/6569afb96f558703 – 101010 Jun 26 '14 at 11:52
  • @JoachimPileborg It doesn't for GCC4.9 either this feature is not implemented yet. – 101010 Jun 26 '14 at 12:02
  • @40two Clang 3.4 but I ran it from the cppreference page. For some reason it works there. – David G Jun 26 '14 at 12:07
  • 1
    It works from cppreference because clang's standard library, [libc++](http://libcxx.llvm.org/), is used. They implemented C++11 back in 2011 (because, unlike GCC's library, there was nothing to be backwards-compatible with) – Cubbi Jun 26 '14 at 12:53
  • For reference, it appears to be available in GCC 5.1 (see row 27.8 [here](https://gcc.gnu.org/onlinedocs/gcc-5.1.0/libstdc++/manual/manual/status.html#status.iso.2011)). – chappjc Oct 23 '15 at 23:29

1 Answers1

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

Billy ONeal
  • 104,103
  • 58
  • 317
  • 552