Problems with stdio.byLine() in D Book
Andrej Mitrovic
andrej.mitrovich at gmail.com
Thu Dec 16 11:01:22 PST 2010
This works fine for me:
import std.stdio;
import std.string;
void main(string[] args)
{
uint[string] freqs;
foreach(lines; stdin.byLine()) {
foreach(word; split(strip(lines))) {
++freqs[word.idup];
}
}
foreach(key, value; freqs){
writefln("%6u\t%s", value, key);
}
getchar();
}
Perhaps you missed an import
On 12/16/10, Chris A <CodexArcanum at gmail.com> wrote:
> Hey all, I'm going over some examples in Alexandrescu's book, but I guess
> something has changed in the language because the example isn't working for
> me.
>
> The simple example:
>
> void main(string[] args)
> {
> uint[string] freqs;
> foreach(lines; stdin.byLine()) {
> foreach(word; split(strip(lines))) {
> ++freqs[word.idup];
> }
> }
> foreach(key, value; freqs){
> writefln("%6u\t%s", value, key);
> }
> din.getc();
> }
>
>
> This throws an error during compile, like:
> main.d(11): Error: no property 'ByLine' for type '_iobuf'
> main.d(11): Error: function expected before (), not 1 of type int
> main.d(11): Error: foreach: int is not an aggregate type
>
> So seemingly byLine is no longer an existing function on stdin. What is the
> current version of what this code is trying to do?
>
More information about the Digitalmars-d-learn
mailing list