I have a 1D vector(Vp_cpp) and I want to convert to 2D vector(declared as Vp_2D). However, my implementation is somewhat not correct because it couldn’t be able to reach the line “Out from inner loop”.
std::vector<double> Vp_cpp;
std::vector<std::vector<double> > Vp_2D;
Vp_2D.resize(N_cpp);
for (int i = 0; i < N_cpp; ++i)
Vp_2D[i].resize(N_cpp);
for (int j = 0; j < N_cpp; j++)
for (int k = 0; k < N_cpp; k++)
{
cout << "Beginning inner loop" << endl;
Vp_2D[i_cpp][i_cpp2] = Vp_cpp[i_cpp2];
cout << "Out from inner loop" << endl;
}
What could be wrong?
This line seems wrong to me:
I would write:
where
iis used to iterate overVp_cpp. It should be initialized to 0 before thefor (int j, ...loop.