Reading a single whitespace-separated word from stdin
bearophile via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue May 6 00:31:12 PDT 2014
Mark Isaacson:
> I'm trying my hand at reading from standard input and having
> little luck. In particular, I would like to be able to do the
> rough equivalent of C++'s:
>
> cin >> myString;
There isn't always a 1:1 mapping between C++ and D. In D if you
want a single word you usually read the whole line (with a
byLine) and then you use split or splitter to take the single
words.
Something like this (untested):
foreach (line; stdin.byLine) {
immutable words = line.chomp.idup.split;
}
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list