I have a vector that will have an unknown number of rows and 3 columns. The vector should be constructed as follows: a statistical test is made, if it pass a threshold the vector should store infos about it. What I am doing is:
vector< vector < int > > validated_edge_list;
validated_edge_list.resize(1);
validated_edge_list.at(1).resize(3);
for(int i = 0; i < e ; i++)
{
p = gsl_cdf_hypergeometric_P(edge_list[i][2],
k_vec[edge_list[i][1]],
M-k_vec[edge_list[i][1]],
N_vec[edge_list[i][0]]); // n2_matrix[i][j] = M-k_matrix[i][j]
if (p <= bonferroni_lvl)
{
validated_edge_list[c][0] = edge_list[i][0];
validated_edge_list[c][1] = edge_list[i][1];
validated_edge_list[c][2] = edge_list[i][2];
c = c + 1;
validated_edge_list.resize(c+1);
validated_edge_list.at(c+1).resize(3);
}
}
As you can see I am manually adding a new raw each time. It gives me the following error:
terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 1) >= this->size() (which is 1)
Aborted (core dumped)
I can assume that I am doing something wrong and I also think that I should use the push_back option, but I don't know how.
How can I fix this? (I am new with C++.)