PHP'nin fgets Eşdeğer Bir C + + (?)

0 Cevap php

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; }

Daha iyi bir çözüm var mı?


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.

Ben bu konuda çok seçici davranıyorum, üzerine beni aramaktan çekinmeyin. Ben sadece benim yöntemi geliştirmek için bir yol olup olmadığını görmek için umuyorum.

0 Cevap