Access Violation when accessing Dynamic Array
tsbockman via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Jan 2 09:05:36 PST 2016
On Saturday, 2 January 2016 at 16:48:41 UTC, Jack wrote:
> 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.
Your example does not compile, even after I add the required
imports (std.algorithm and std.stdio):
Error: template std.algorithm.mutation.stripLeft cannot
deduce function from argument types !()(string)
Please test your example code before asking for help.
More information about the Digitalmars-d-learn
mailing list