Calling readln() after readf
Gary Chike
chikega at gmail.com
Sun Jun 19 22:52:35 UTC 2022
On Saturday, 24 April 2021 at 22:13:45 UTC, Ali Çehreli wrote:
> On 4/24/21 7:46 AM, PinDPlugga wrote:
> ...
> As a general solution, you can use a function like this:
>
> auto readLine(S = string)(File file = stdin) {
> while (!file.eof) {
> auto line = file.readln!S.strip;
> if (!line.empty) {
> return line;
> }
> }
>
> return null;
> }
>
> Ali
Hi Ali,
Being a new D learner, I've noticed this behavior as well. Thank
you for providing the 'readLine' function! Would it be considered
poor coding style to intercept the stream between readf and
readln with the following statement? :
```d
auto catcher = readln.strip;
```
P.S. I love your book on D! :)
Cheers,
Gary Chike
More information about the Digitalmars-d-learn
mailing list