int dArray[1600][32];
vector < vector <int> > dVector;
n= 1600; k = 32
dVector.resize(n);
for(int i = 0 ; i < n ; ++i){
dVector[i].resize(k);
}
std::copy ( dArray, dArray + tmp_c, std::back_inserter (dVector));
How do i use the std::copy ( or any other function ) to copy an multi dimensional array to a vector and vice versa?
You can't do it directly, but with an intermediate step. Depending on your requirements, something like this vector_wrapper
might work for you
#include <vector>
template<typename T, int N> struct vector_wrapper {
vector_wrapper(T (&a)[N]) {
std::copy(a, a + N, std::back_inserter(v));
}
std::vector<T> v;
};
int dArray[1600][32];
std::vector<vector_wrapper<int, 32> > dVector;
int main(int argc, char **argv)
{
std::copy(dArray, dArray + 1600, std::back_inserter(dVector));
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With