variables from file into stuct

Im having trouble getting getting this to work right for me, I need the values of x1,y1... to save into the array of triangles[]. This is reading from a file, where each line is coordinates of a triangle. When i just display x1,y1..... it works as expected, but when they enter into the array, it just enters the last value of x1,y1... I need each line to be saved to into the array of triangles[]. Ive been stuck on this for a while now. Any help would be appreciated

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
	ifstream datafile;
	datafile.open(baseDir + "triangles6.csv");
	while (!datafile.eof()) {
		datafile >> buffer;
		splitStringByCommas(buffer, oneTriangleData);
		double x1 = atof(oneTriangleData[0].c_str());
		double y1 = atof(oneTriangleData[1].c_str());
		double x2 = atof(oneTriangleData[2].c_str());
		double y2 = atof(oneTriangleData[3].c_str());
		double x3 = atof(oneTriangleData[4].c_str());
		double y3 = atof(oneTriangleData[5].c_str());
		string color = oneTriangleData[6];
	cout << x1 << " " << y1 << " " << x2 << " " << y2 << " " << x3 << " " << y3 << " " << color << endl;
	triangles[0].a = { x1, y1 }; triangles[0].b = { x2, y2 }; triangles[0].c = { x3, y3 }; triangles[0].color = color;
	triangles[1].a = { x1, y1 }; triangles[1].b = { x2, y2 }; triangles[1].c = { x3, y3 }; triangles[1].color = color;
	triangles[2].a = { x1, y1 }; triangles[2].b = { x2, y2 }; triangles[2].c = { x3, y3 }; triangles[2].color = color;
	triangles[3].a = { x1, y1 }; triangles[3].b = { x2, y2 }; triangles[3].c = { x3, y3 }; triangles[3].color = color;
	triangles[4].a = { x1, y1 }; triangles[4].b = { x2, y2 }; triangles[4].c = { x3, y3 }; triangles[4].color = color;
	triangles[5].a = { x1, y1 }; triangles[5].b = { x2, y2 }; triangles[5].c = { x3, y3 }; triangles[5].color = color;
	triangles[6].a = { x1, y1 }; triangles[6].b = { x2, y2 }; triangles[6].c = { x3, y3 }; triangles[6].color = color;
	triangles[7].a = { x1, y1 }; triangles[7].b = { x2, y2 }; triangles[7].c = { x3, y3 }; triangles[7].color = color;
	triangles[8].a = { x1, y1 }; triangles[8].b = { x2, y2 }; triangles[8].c = { x3, y3 }; triangles[8].color = color;
	triangles[9].a = { x1, y1 }; triangles[9].b = { x2, y2 }; triangles[9].c = { x3, y3 }; triangles[9].color = color;
	triangles[10].a = { x1, y1 }; triangles[10].b = { x2, y2 }; triangles[10].c = { x3, y3 }; triangles[10].color = color;
	triangles[11].a = { x1, y1 }; triangles[11].b = { x2, y2 }; triangles[11].c = { x3, y3 }; triangles[11].color = color;
	triangles[12].a = { x1, y1 }; triangles[12].b = { x2, y2 }; triangles[12].c = { x3, y3 }; triangles[12].color = color;
	triangles[13].a = { x1, y1 }; triangles[13].b = { x2, y2 }; triangles[13].c = { x3, y3 }; triangles[13].color = color;
	triangles[14].a = { x1, y1 }; triangles[14].b = { x2, y2 }; triangles[14].c = { x3, y3 }; triangles[14].color = color;
	triangles[15].a = { x1, y1 }; triangles[15].b = { x2, y2 }; triangles[15].c = { x3, y3 }; triangles[15].color = color;
	triangles[16].a = { x1, y1 }; triangles[16].b = { x2, y2 }; triangles[16].c = { x3, y3 }; triangles[16].color = color;
	triangles[17].a = { x1, y1 }; triangles[17].b = { x2, y2 }; triangles[17].c = { x3, y3 }; triangles[17].color = color;
	triangles[18].a = { x1, y1 }; triangles[18].b = { x2, y2 }; triangles[18].c = { x3, y3 }; triangles[18].color = color;
	triangles[19].a = { x1, y1 }; triangles[19].b = { x2, y2 }; triangles[19].c = { x3, y3 }; triangles[19].color = color;
	triangles[20].a = { x1, y1 }; triangles[20].b = { x2, y2 }; triangles[20].c = { x3, y3 }; triangles[20].color = color;
	triangles[21].a = { x1, y1 }; triangles[21].b = { x2, y2 }; triangles[21].c = { x3, y3 }; triangles[21].color = color;

		tCount++;

	}
	datafile.close();
Topic archived. No new replies allowed.