Need help displaying a stack

I know i've been asking a lot help lately displaying STL's but I have a couple assignments due tomorrow and apparently my book doesnt contain a chapter STL's and the few powerpoint slides I have are rather vague.

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
44
45
46

#include<iostream>
#include <stack>
using namespace std;

int main()
{
	stack<int, list<int> > stck;

	

	//push the even values 2-10 onto the stack

	stck.push(2);
	
	stck.push(4);
	
	stck.push(6);
	
	stck.push(8);
	
	stck.push(10);

	//display the value at the top of the stack

	cout<<"List Elements: ";
	for(stck = list.begin(); stck != list.end(); stck++)
    cout<<*stck<<" ";


	//pop two values off of the stack

	stck.pop();
	stck.pop();


	//display the new top of the stack

	cout<<"List Elements: ";
	for(stck = list.begin(); stck != list.end(); stck++)
    cout<<*stck<<" ";


	return 0;
}



I seem to be getting an error when I define my stack with the word "list" being underlined, and am also unsure of how to properly display my stack. Help is greatly appreciated. thank you!
Not all people consider STL to be part of the standard library. Are you sure your book don't just call it something else?

To use std::list you must #include <list> .

std::stack doesn't support iterators so you can't iterate over the stack without removing elements. If you must be able to iterate over the stack use a std::vector or a std::deque instead.
Last edited on
Topic archived. No new replies allowed.