I'm trying to create a matrix, using 2D vector. I don't understand why compiler gives me error of segmentation fault. Any idea? :)
here is my code:
#include <iostream>
#include <vector>
using namespace std;
int main(){
vector < vector <int> > Board;
int n;
cout<<"Enter size: ";
cin>>n;
Board.resize(n);
//Initialize with something
for(int ii=0; ii<n; ii++)
{
for (int jj=0; jj<n; jj++)
Board[i][j]=1;
}
//Show vector
for(int i=0; i<n; i++)
{
for (int j=0; j<n; j++)
{
cout<<Board[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
I also tried to fill vector with the expression "Board.at(i).at(j)=1" but nothing happen.