Inputting text to an object then object into a list

I am currently writing a program that should read sets of coordinates from a file and place these coordinates in an object, before adding the object to a list of such objects.

Here is the method I am trying to use, v1 is the object, which is created by a constructor which I know works, the file reads in the X and Y coordinates and stores then within the object.

But would anyone possibly be able to explain to me how I can add this object to a list?

I am using the standard library list as writing my own did not turn out well and later I will need the list to be doubly linked.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  int import()
{
	ifstream Input;
	Input.open("Swallow.txt");
	list<int> Xlist;
	

	while (!Input.eof())
	{
		int x;
		int y;

		Input >> x >> y;

		Vertex v1( x, y);

		if (Input.eof()) break;

	}

	Input.close();
	cout << "Import finished" << endl;

}


Thank you in advance for any help

Jack Perry
The same way you add anything else to a list. The type would be <Vertex> assuming that is your object, so
 
list<vertex> v1;

Then just add to it like
1
2
3
4
5
6
7
8
9
10
11
12
13
while (!Input.eof())
{
	int x;
	int y;

	Input >> x >> y;

	//Vertex v1( x, y);
        v1.push_back(Vertex(x, y));

	if (Input.eof()) break;

}
Thanks you very much! I feel quite silly now.
Topic archived. No new replies allowed.