Help with Associative array problems.

Spacen Jasset spacenjasset at yahoo.co.uk
Wed Apr 2 02:30:34 PDT 2008


The program below does not print what it should, either using a File or 
the TArrayStream.

It prints this:

user at vm-fruitbat:~$ dmd t.d
user at vm-fruitbat:~$ ./t
Error: 4invalid UTF-8 sequence
Material user at vm-fruitbat:~$



I can "fix" it by saying:

	m[words[1].dup] = 1

But why does the original 'go wrong'



import std.stdio;
import std.string;
import std.stream;

void main()
{
	//Stream file = new File("test.txt");
         TArrayStream!(char[]) file =
		new TArrayStream!(char[])("newmtl one\nnewmtl two");

	int [char[]]	m;
	foreach(ulong line_no, ref string line; file) {
		string words[] = line.split();
       		m[words[1]] = 1; 	
	}
         foreach (char[] k, ref int v; m) {
		writefln("Material %s", k);
	}
}


More information about the Digitalmars-d-learn mailing list