You get this error because you didn't resize the array. Accessing indexes without giving proper size to the array results in invalid index.
For your use case, I would suggest you use append
, which increases size by 1 and adds the line at the end of the array:
test.append(file.get_line())
In case you know in advance how many lines there is:
test.resize(line_count)
...
test[i] = file.get_line()
Another thing to note: array indexes start from 0, not 1.