Essentially what I'm looking for is a function with the following prototype: string getln(istream);
All I need it to do is work like PHP's fgets()
, that is, take an input stream as a parameter and return the next line from the stream.
I feel like my current approach is somewhat bulky for creating a temporary variable each time it's called:
string getln(istream &input) { string rtn; getline(input, rtn); return rtn; }
Are there any better solutions?
Background:
I'm not looking for a function like this for assignment operations (like some_str = getln(ifile);
) but I'm trying to use it as a data source for a stringstream. Ultimately I want a smaller version of getline(ifile, tmp); string_str.str(tmp);
that looks a bit more like string_str.str(getln(ifile));
but without the overhead of my example function creating a temp variable each time.
If I'm being too picky about this, feel free to call me out on it. I'm just hoping to see if there's a way to improve on my method.