I want to copy one vector to another. I have two similar types of codes. The 1st one ("check_1.C") works but the second one did not work ("check_2.C").
Could you please suggest and explain.
1st code (working):
double Refm[10] = {4 , 9 , 18 , 32 , 52 , 80 , 118 , 172 , 206 , 300};
double p_low[9] = {0.88, 0.72, 0.89, 0.84, 0.75, 0.71, 0.79, 0.69, 0.66};
double p_high[9] = {0.14, 0.19, 0.16, 0.24, 0.21, 0.27, 0.22, 0.29, 0.25};
const int centrality_bin = 9;
void check_1()
{
vector<vector<double> > eff_cen;
eff_cen.resize(Refm[9]+1);
vector<vector<double> > eff;
for(int jj = 0; jj < centrality_bin; jj++)
{
eff_cen[jj].push_back(p_low[jj]);
eff_cen[jj].push_back(p_high[jj]);
cout<<"eff_cen[" << jj << "] = ";
for(size_t kk=0; kk<eff_cen[jj].size(); kk++) cout<<eff_cen[jj].at(kk)<<" ";
eff.push_back(eff_cen[jj]); // I CAN COPY CORRECTLY
for(size_t nn=0; nn<eff[jj].size(); nn++) cout<<eff[jj].at(nn)<<" ";
cout << endl;
}
}
2nd code (not working):
double Refm[10] = {4 , 9 , 18 , 32 , 52 , 80 , 118 , 172 , 206 , 300};
double p_low[9] = {0.88, 0.72, 0.89, 0.84, 0.75, 0.71, 0.79, 0.69, 0.66};
double p_high[9] = {0.14, 0.19, 0.16, 0.24, 0.21, 0.27, 0.22, 0.29, 0.25};
void check_2()
{
vector<vector<double> > eff_cen;
eff_cen.resize(Refm[9]+1);
vector<vector<double> > eff;
//eff.resize(Refm[9]+1);
for(int z = 0; z < 9; z++) {
for(int jj = Refm[z]+1; jj <= Refm[z+1]; jj++)
{
eff_cen[jj].push_back(p_low[z]);
eff_cen[jj].push_back(p_high[z]);
cout<<"eff_cen[" << jj << "] = ";
for(size_t kk=0; kk<eff_cen[jj].size(); kk++) cout<<eff_cen[jj].at(kk)<<" ";
eff.push_back(eff_cen[jj]); // COPY DOES NOT WORK
for(size_t nn=0; nn<eff[jj].size(); nn++) cout<<eff[jj].at(nn)<<" "; cout << endl;
}
}
}
Aucun commentaire:
Enregistrer un commentaire