Your vector a
contains 3 empty vectors, but you treat them as if they were not here:
a[i][j]=i*3+j; // a[i] has size 0 here
This out of bounds access is undefined behaviour. The reason is that this
a.resize(3); //cols
is not dong what you think it is. It essentially has no effect, because a
is already size 3 at this stage.
If you want a 3 by 3 vector of vectors, initialize a
like this:
vector<vector <int> > a(3, std::vector<int>(3));