string - Initialize a vector of vectors where not all vectors are of same size C++ -
i have data this.
static const double v1_arr={2,3,4} vector<double> v1_vec(v1_arr, v1_arr + sizeof(v1_arr[0])) static const double v2_arr={9,6} vector<double> v2_vec(v2_arr, v2_arr + sizeof(v2_arr[0])) static const double v3_arr={9,6,7,6} vector<double> v3_vec(v3_arr, v3_arr + sizeof(v3_arr[0]))
how initialize vector of vectors v_v
contains 3 above vectors?
if using compiler supports c++11
can do
vector<vector<double>> v_3{v1_vec, v2_vec, v3_vec};
if not have like
vector<vector<double>> v_3; v_3.push_back(v1_vec); v_3.push_back(v2_vec); v_3.push_back(v3_vec);
note if can use c++11
features, can initialize other vectors this
vector<double> v1_vec{1.0, 2.0, 3.0};
and skip intermediate v1_arr
.
Comments
Post a Comment