So I declared the following map in C++:
typedef vector<Vector2D> stackPoints;
typedef map<int, stackPoints> mapPoints;
mapPoints drawingPoints;
After adding values to it, I want to output all the elements in it, but the vectors at the different key positions are not of the same size:
I am using the following two for-loops that don't work. Sometimes the program crashes at runtime and gives me the out of range vector error.
for (int j = 0; j < drawingPoints.size(); j++)
{
for (int i = 0; i < drawingPoints[j].size(); i++)
{
cout << "(...)" << endl
}
}
It seems to me that the inner for-loop has the be went through a constant amount of times, as if the following scenario wasn't possible:
1) The first vector has a size of 1, so the inner for-loop will be executed once.
2) Then the second vector of the map has a size of 5 and now I want the for-loop to be went through 5 times, but this seems to not work.
** Edit **
I am using the integer key as a counter, so I increment it by 1 when I add another pair.