2D vector problem

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
cout<<"How many points are there?\n";

	int number;

	cin>>number;

	vector<vector<node*> >points(number,vector<node*>(0));

	for(int i=0;i<number;i++)		//labels each point
	{
		node* newNode=new node;

		points[i][0]=newNode;
		cout<<"Label point "<<i+1<<"\n";

		cin>>points[i][0]->label;
	}

Why isn't this code working? im trying to assign a pointer to the vector elements, but the program terminates once it gets to the "points[i][0]=newNode" Anyone know whats wrong?
Last edited on
Each inner vector has a size of 0, so [i][0] is out of bounds.
Last edited on
try points[i][0] = *newNode;
Well actually you'd need to do points[i].push_back(newNode);
Also that wouldn't work because you're trying to deference it, type mis-match.
Last edited on
Topic archived. No new replies allowed.