Why am I getting error in "res.push_back(num);"


#1

vector<vector > mat;
vector res;
if(A >= 1){
res.push_back(1);
mat.push_back(res);
res.clear();
}
if(A >= 2){
res.push_back(1);
res.push_back(1);
mat.push_back(res);
res.clear();
}
for(int i = 3; i < A; i++){
vector res;
res.push_back(1);
for(int j = 0; j < A-2; j++){
int num =mat[i-1][j] + mat[i-1][j+1];
res.push_back(num);
}
res.push_back(1);
mat.push_back(res);
}
return mat;


#2

You have declared res and mat vector incorrectly. It should be like this -> vector<vector> mat and vector res.


#3

.push_back() will create error as the array has been initialised as all zeros.
Use res[j]= …
and what the above guy said