getline();

i am confused with syntax
which one is correct



1
2
3
4
5
ifstream fileptr;
string line;
fileptr.getline(line,100);
or
getline(fileptr,line)
In this case line 5.

istream::getline() is used when you store data in a char array http://www.cplusplus.com/reference/istream/istream/getline/
When you have an std::string you need to use a global std::getline() http://www.cplusplus.com/reference/string/string/getline/
closed account (S6k9GNh0)
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 member function as well but it only accepts char *: http://www.cplusplus.com/reference/istream/istream/getline/

What you're looking for is http://www.cplusplus.com/reference/string/string/getline/ 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
means there are two getline() function in two different libraries..?
thank you!
got it
Topic archived. No new replies allowed.