int i = 0;
int j = 0;
vector<vector<int>> normal;
vector< vector<int> >::iterator row;
vector<int>::iterator col;
for (i = 1; i < 10; i++) {
for (j = 1; j < 10; j++) {
normal[i].push_back(j);
}
}
Can someone explain me what l am doing wrong? during my compiling I got the error "Vector subscript out of range"
vector subscript out of range means "you asked for an element from the vector, but the vector is not of that size". e.g. vector<int> vec; vec.push_back(42); vec[1] // oops, 42 is vec[0]
Vectors in C++ are sequence containers representing arrays that can change their size during runtime. They use contiguous storage locations for their elements just as efficiently as in arrays, which means that their elements can also be accessed using offsets on regular pointers to its elements.
You never add any elements to normal
before trying to use normal[i]
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With