Range violation error when reading from a file
Samir
samir at aol.com
Sun Jun 16 22:47:14 UTC 2019
I am trying to read from a text file using the following code:
import std.stdio;
import std.string;
void main() {
File file = File("test.txt");
string line;
while (!file.eof()) {
line = strip(file.readln());
if (line[0] == '>') { // line 10
writeln(line[1..$]);
}
else {
writeln(line);
}
}
}
and I get the following error AFTER the last line is processed:
core.exception.RangeError at readfile.d(10): Range violation
----------------
??:? _d_arrayboundsp [0x448efa]
??:? _Dmain [0x4459f7]
Any idea what I am doing wrong? When processing the if statement
or writing the slice, am I inadvertently trying to read a
non-existent line in the file?
Thanks in advance
Samir
More information about the Digitalmars-d-learn
mailing list