问题
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
andswap
operations onbasic_ios
.- Missing
io_errc
andiostream_category
.ios_base::failure
is not derived fromsystem_error
.- Missing
ios_base::hexfloat
.
more info here
来源:https://stackoverflow.com/questions/24429441/c-compiler-does-not-recognize-stdstringstreamswap