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))
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.
source share