I can make getline do a file read OK if the buffer is type char*, but not type string. ie:
{below code is skeleton, some nonrelevant aspects oimitted}
char* buf ; // this works
buf = new char [21] ;
ifstream ifs ;
...........
(void) ifs.getline (buf, 20) ;
using namespace std ; // This gives a compile error on the getline
string buf ;
buf.resize(21) ;
ifstream ifs ;
.........
(void) ifs.getline (buf, 20) ;
This isn't a stopper, I can simply do a type conversion, but would prefer ot keep with strings if possible. According to my C++ std library reference, a string arg should be OK, It works under MSVS2015.
This works in our code base across 2010 <--> 10.1 inclusive - where the ifstream is passed as an argument to the call to std::getline, as opposed to your usage:
std::ifstream infile(filename.c_str() );
if (infile.is_open() )
{
while (infile.good() )
{
std::string line;
std::getline(infile, line);
// other stuff here
}
infile.close();
}
Connect with Us