A std::vector can be constructed using a C-array like so: std::vector<int> vec(ary, ary + len). What is the proper way to construct a std::vector<std::vector<int> >?
I’ve been brute-forcing the issue by manually copying each element into the vector, clearly this is not the intent, but it works.
int map[25][18] = { /*...DATA GOES HERE...*/ }
std::vector<std::vector<int> > m(18, std::vector<int>(25, 0));
for(int y = 0; y < 18; ++y) {
for(int x = 0; x < 25; ++x) {
m[y][x] = map[y][x];
}
}
In C++11, you can optionally replace the last line with the following to remove a little noise: