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.
#include<iostream>
#include <stack>
usingnamespace 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.