Efficiently streaming data to associative array

Anonymouse via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Aug 8 12:43:49 PDT 2017


On Tuesday, 8 August 2017 at 16:00:17 UTC, Steven Schveighoffer 
wrote:
> I wouldn't use formattedRead, as I think this is going to 
> allocate temporaries for a and b.

What would you suggest to use in its stead? My use-case is 
similar to the OP's in that I have a string of tokens that I want 
split into variables.

import std.stdio;
import std.format;

void main()
{
     string abc, def;
     int ghi, jkl;

     string s = "abc,123,def,456";
     s.formattedRead!"%s,%d,%s,%d"(abc, ghi, def, jkl);

     writeln(abc);
     writeln(def);
     writeln(ghi);
     writeln(jkl);
}


More information about the Digitalmars-d-learn mailing list