|Posted by Tyro||PermalinkReply|
I'm using the following to read arrays from the command line (or redirected file) but am having some issues that I have not been able to solve on my own. Would appreciate if a little guidance.
void f(T)(ref T a)if(isArray!T)
a.length = 100;
while(readf(" %s", &a[i++])) // #1
if(i == a.length) a.length *= 2;
how do it terminate the input (or clear the buffer) such that subsequent calls to readf are not ignored?
f(i); // no matter how many time I call readf() after this point it is all always ignored
readf(" %s", &d); // not called
how do i read a string such that whitespace (all or one of my choosing) delineate the string boundary?
readf(" %s ", &data) sort of does the trick for spaces but it leaves all newlines embedded in substrings. Assuming that input is provided one string per line, readf(" %s\n", &data) works similar to #1 above, however if there is multiple words per line separated by spaces an exception is immediately thrown from std.format.