# Answer to Question #16718 in C++ for sahar

Question #16718

How to fill a two-dimensional vector of size n in n +1 with two for?

my code:

vector<vector<int> >v(n,vector<int>(n+1));

for(unsigned int i=0 ; i<n+1 ; i++){

for(unsigned int j=0 ; j<n ; j++){

cin>>v[i][j];

}

}

but it has segmantation fault error!!!!

tnx for helping

my code:

vector<vector<int> >v(n,vector<int>(n+1));

for(unsigned int i=0 ; i<n+1 ; i++){

for(unsigned int j=0 ; j<n ; j++){

cin>>v[i][j];

}

}

but it has segmantation fault error!!!!

tnx for helping

Expert's answer

Here is corrected code

int v[n+1][n];

for(unsigned int i=0 ; i<n+1 ; i++){

& for(unsigned int j=0 ; j<n ; j++){

& cin>>v[i][j];

& }

}

int v[n+1][n];

for(unsigned int i=0 ; i<n+1 ; i++){

& for(unsigned int j=0 ; j<n ; j++){

& cin>>v[i][j];

& }

}

## Comments

## Leave a comment