Need help reading in string with getline()

Hi,

I'm trying to read a line of text from a file into a string variable. The easiest way I could see to do this was (I thought) the getline() method, but when I try to use it, I get a compile error saying that I have to use getline() with different parameters (that is, as opposed to "no parameters"). I've looked at a c++ reference, and I see the methods that are available, but they don't make the most intuitive sense to me (ie, how does one declare a cstring? Because .getline() apparently needs one passed to it).

Ultimately, all I have to do is read a line of text from an fstream into a string. Any way I can make that happen is fine by me. So if you guys have any suggestions, it'd be a great help.

Thanks~
Last edited on
The std::iostream::getline() methods are not std::string friendly. The std::getline() function is.

 
#include <string> 
1
2
string s;
getline( myfile, s );

Hope this helps.
Topic archived. No new replies allowed.