What compiler are you using? I think this is possibly a quirk in the implementation of your STL vector class. In Visual Studio 2005 vector<int> mtr; mtr.reserve(5); mtr[2]=7; throws "vector subscript out of range"; I'd suggest that your implementation of STL could have a bug in this regard.

I noticed in the last bit of code that you use mtr.resize() rather than mtr.reserve().
See http://www.cplusplus.com/reference/s...r/reserve.html
and compare it with http://www.cplusplus.com/reference/s...or/resize.html
There's no indication in the reserve() doc that this actually creates new elements. The VS2005 code above throws no exceptions if I change reserve() to resize().

Also changing mtr[i].reserve(length); to mtr[i].resize(length); in your last code means the code throws no exceptions.

So the "inconsistency" is that resize() doesn't do the same as reserve(). RTFM! :-)