Displaying a List using an iterator.

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
42
43

#include<list>
#include <iostream>

using namespace std;

int main()
{
	list<double> numList;

	//add the values 12.7, 9.65, 8.72 and 4.69 to numList
	numList.push_back(12.7);
	numList.push_back(9.65);
	numList.push_back(8.72);
	numList.push_back(4.69);


	cout << "numList contains: "<< endl;
	//display the list using an iterator

	


	list<double>::iterator itt = numList.begin();
	itt++;
	itt++;

	//remove the element pointed to by itt
	numList.erase(itt);

	//reverse the list
	numList.reverse();


	cout << "\nnow numList contains: " << endl;
	//display the list again

	

	return 0;
}




I am having trouble finding out the correct code to display the list using an iterator. The notes provided by my school for this section are very vague, and honestly about 3 slides total for all of Lists. Any help would be welcome. Thank you.
1
2
3
4
5
list<double>::iterator dbl;
   for(dbl=numList.begin(); dbl!=numList.end(); dbl++)
   {
      cout << *dbl << endl;
   }
Topic archived. No new replies allowed.