There is a certain piece of code that creates a two-dimensional field m [x] [y] and clogs it with zeros:
std::vector<std::vector<int> > vector_map; vector_map.push_back(std::vector<int>() ); vector_map.resize(count_h); for (unsigned int y = 0; y < count_h; y++) { for (unsigned int x = 0; x < count_w; x++) { vector_map[x].push_back(0); } } Initialization of count_w and count_h occurs at the moment of calling the function in which the given code is contained. AND...
- How to withdraw the whole thing? It is desirable to implement this using the same two cycles as above.
- How to get access to an arbitrary field of the resulting matrix and, if necessary, change it?
I was able to clog values, as well as their conclusion:
std::vector<int> vector_map; vector_map.resize(count_h * count_w); for (unsigned int y = 0; y < count_h; y++) { vector_map.push_back(y); for (unsigned int x = 0; x < count_w; x++) { vector_map.push_back(x); } } for (unsigned int y = 0; y < count_h; y++) { for (unsigned int x = 0; x < count_w; x++) { std::cout << vector_map[x*y]; } std::cout << std::endl; } The result was something like this:
0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 But how to get access and change any arbitrary element - I can't imagine the mind. I hope for your help.
Thank you in advance.