What would be the easiest way to store a series of vector coordinates
inside a data structure like stl vectors or other stl structures if I
don't want to deal with dynamic memory allocation with 2D arrays
myself?
Create a struct called vector. E.g.
struct Vector2D { double x; double y; }
Then create a vector of Vector2Ds.
std::vector<Vector2D> coords;
Of course, stl provides a class called pair if it actually turns out
you only need a 2-dimensional vectors. So, you could do:
using namespace std;
vector<pair<double> > coords;
coords.push_back(make_pair(1.0, 2.0));
coords.push_back(make_pair(3.0, 4.0));
I suspect this is not the case, but if you want to store coordinates
of differing dimensions, like for example maybe the first item is a 2d
coord vector, and the second item is a 3d coord vector, you can do
something like this:
vector<vector<double> > coords;
vector<double> temp;
temp.push_back(1.0); temp.push_back(2.0);
coords.push_back(temp);
temp.clear();
temp.push_back(1.0); temp.push_back(2.0); temp.push_back(3.0);
coords.push_back(temp);
First or second method is probably most suitable though. Note that
the code is identical if you want to use a list intead of a vector,
just change 'vector' in the type definition to 'list'.