problems with DPL example.
%u
foo at bar.com
Mon Oct 10 11:48:21 PDT 2011
Thanks. It works, but I get something weird in the output. I get
the problem if I run it in a dos prompt or in a cygwin prompt:
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
D>echo hello | wordcount2.exe
0 hello
std.stdio.StdioException at std\stdio.d(2156): Bad file descriptor
----------------
42A910
42A787
40318A
40239C
402141
403798
4037D7
4033D3
465D71
----------------
Do you know what this is caused by?
thanks.
Here's the code again:
import std.stdio, std.string, std.array;
void main() {
uint[string] dictionary;
foreach( line; stdin.byLine()) {
// Break sentence into words
// Add each word in the sentence to the vocabulary
foreach( word; splitter(strip(line))) {
if( word in dictionary) continue; // Nothing to do.
auto newID = dictionary.length;
dictionary[word.idup] = newID;
writeln( newID, '\t', word);
}
}
return;
}
thanks.
More information about the Digitalmars-d-learn
mailing list