Access Violation when accessing Dynamic Array

Jack via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jan 2 08:48:41 PST 2016


So yeah I've been trying to experiment with the language when I'm 
met with an Access Violation error.

So I've extracted a string from a file and used it as an index 
for a dynamic array. Stripped code sample is :

/////////////////////////////

void foo()
{
string[string] custom;
string keyword;
string script;

File file = File("read.txt", r);
while(!file.eof())
{
script ~= file.readln();
}

foreach(a; script)
{
keyword ~= a; //assuming keyword is "Mario"
}
keyword = stripLeft(keyword);
custom[keyword] = "sample string";

writeln(keyword); // Outputs "Mario"
writeln(custom[keyword]); // Works fine. Outputs "sample string".
writeln(custom["Mario"]); // First-chance exception: 0xc0000005: 
Access violation

}
/////////////////////////////

So am I doing something wrong here? Did I mess with something 
that I shouldn't have?
If it helps I'm using dmd v.2.069.2 on Win7 64-bit.


More information about the Digitalmars-d-learn mailing list