On Saturday, 10 December 2016 at 08:03:00 UTC, biozic wrote:
This would do the same. I wouldn't say it's a trick.

    import std.format : formattedRead;
    import std.stdio : writefln;

    string ipAddr = "";
    int a, b, c, d;
    formattedRead(ipAddr, "%d.%d.%d.%d", &a, &b, &c, &d);
    writefln("%s %s %s %s", a, b, c, d);

Well, you know, that's one of the not so great things about Dlang... you cannot even trust the provided examples, if there are any:

C:\Temp\D>more formattedReadIps.d
import std.format;
string s = "hello!124:34.5";
string a;
int b;
double c;
formattedRead(s, "%s!%s:%s", &a, &b, &c);
assert(a == "hello" && b == 124 && c == 34.5);

C:\Temp\D>dmd -v formattedReadIps.d
binary    C:\D\dmd2\windows\bin\dmd.exe
version   v2.072.1
config    C:\D\dmd2\windows\bin\sc.ini
parse     formattedReadIps
formattedReadIps.d(6): Error: unexpected ( in declarator
formattedReadIps.d(6): Error: basic type expected, not "%s!%s:%s"
formattedReadIps.d(6): Error: found '"%s!%s:%s"' when expecting ')' formattedReadIps.d(6): Error: no identifier for declarator formattedRead(s, _error_) formattedReadIps.d(6): Error: semicolon expected following function declaration
formattedReadIps.d(6): Error: declaration expected, not ','
formattedReadIps.d(7): Error: declaration expected, not 'assert'

Reply via email to