Parsing a string from stdin using formattedRead

Adam D. Ruppe destructionator at gmail.com
Thu Dec 7 15:09:14 UTC 2017


On Wednesday, 6 December 2017 at 18:47:03 UTC, Mark wrote:
> formattedRead(readln(), "%s %s", first_name, last_name);

You could write a little wrapper function to do that

uint myformattedRead (R, Char, S...)(R r, const(Char)[] fmt, auto 
ref S args) {
     formattedRead(r, fmt, args);
}


It just strips the ref off of the input string but otherwise 
forwards the same thing.

The reason it is ref tho btw is that that allows it to continue 
off a particular input; you can do like

string s;
formattedRead(s, ....)
formattedRead(s, ....) // this one picks up where the last one 
left off


More information about the Digitalmars-d-learn mailing list