There seems to be no getline () overload using RRef for the stream in GCC 4.7.2 and Clang 3.2

I encountered an unexpected compilation error while trying to use getline() with a temporary stream object:

 #include <iostream> #include <string> #include <sstream> using namespace std; int main() { string input = "hello\nworld\nof\ndelimiters"; string line; if (getline(stringstream(input), line)) // ERROR! { cout << line << endl; } } 

It seems that there is no getline() overload that accepts an rvalue reference to the stream object. If I change main() to use lvalue, it compiles and runs as expected:

 int main() { string input = "hello\nworld\nof\ndelimiters"; string line; stringstream ss(inpupt); if (getline(ss, line)) // OK { cout << line << endl; } } 

So, I looked in the C ++ 11 standard and found (Β§ 21.4.8.9) that there must be an overload of getline() that takes an rvalue reference to a stream object.

Am I missing something obvious or is this a mistake? The error occurs with both GCC 4.7.2 and Clang 3.2. I can not check it on VC at the moment.

+4
source share
1 answer

If I compile on OS X with the following line, it compiles successfully. What version of libstdc ++ or libc ++ are you using?

 clang++ -std=c++11 -stdlib=libc++ foo.cc 

libstdC ++ (and libC ++, for that matter) does not yet fully implement the standard C ++ 2011 library. This is apparently one of the missing functions from libstdC ++.

Unfortunately, I do not know of a single resource that accurately lists what is missing in each implementation.

+4
source

All Articles