Sep 8, 2013 at 5:29am UTC
i am confused with syntax
which one is correct
ifstream fileptr; string line; fileptr.getline(line,100); or getline(fileptr,line)
Sep 8, 2013 at 5:42am UTC
In this case line 5.
istream::getline() is used when you store data in a char array
When you have an std::string you need to use a global std::getline()
Sep 8, 2013 at 5:45am UTC
Assuming you've correctly initialized the ifstream and you've opened a file, the second one would be most correct.
The istream class provides a getline
function as well but it only accepts char *:
What you're looking for is
which is a part of the string header. To be quite honest, I'm ignorant of what the standard says is the difference between the two as far as result and consequence goes.
Last edited on
Sep 8, 2013 at 5:47am UTC
Sep 8, 2013 at 5:46am UTC
means there are two getline() function in two different libraries..?
Sep 8, 2013 at 6:03am UTC
Topic archived. No new replies allowed.
General C++ Programming
© cplusplus.com, 2000-2013 - All rights reserved -
Spotted an error? contact us