Is using getline with a fstream reference covered in the standard?
I have three C++ compilers on my system. Two of them compile
the code below without warnings. The third returns the following
error:
t1.cpp:
Error E2285 t1.cpp 14: Could not find a match for
'std::getline<charT,traits,Allocator>(std::ifstrea m,std::string)'
in function A::readfun()
*** 1 errors in Compile ***
If the fstream is not a reference, it compiles without complaint.
BTW, yeah, I know, I haven't opened a file etc. I've
tried to skinny the code down to the minimum that
produes the error.
#include <fstream>
#include <string>
class A {
public:
A(std::ifstream& _inH) : inH(_inH) {}
void readfun();
void readfun1();
private:
std::ifstream& inH;
};
void A::readfun() {
std::string buf;
std::getline(inH, buf);
}
int main() {
std::ifstream fin;
class A x(fin);
return 0;
}