I have searched for a good answer to this question but have been unable to find one. I found the following question, but it does not answer the question below (this question relates to converting a 2D array to a vector, not just a 1D array):
I have the following function that is passed a 2D array as a double pointer and the dimensions of the first and second indices in the array:
std::vector<std::vector<float>> ConvertToVector(const float **a_data,
const int a_d1, const int a_d2)
I want to convert a_data to a 2D vector and return the vector. My only solution so far is to step through each of the elements in the first dimension of the array and push back each element as follows:
std::vector<std::vector<float>> dataVec;
for (int i=0; i<a_d1; i++)
{
std::vector<float> v(a_data[i], a_data[i]+a_d2);
dataVec.push_back(v);
}
return dataVec;
Is there a simpler/more elegant solution than this?