Reputation: 18068
I have a big problem with "program language" called C++. I wanted to print the stack of strings.
void show(stack<string> stos) {
while (!stos.empty()) {
cout << stos.pop() << endl;
}
}
Upvotes: 0
Views: 97
Reputation: 55395
pop()
only removes the top element from the stack and throws it away. It returns void
(nothing) and you can't print that with cout
, obviously. You need:
void show(stack<string> stos)
{
while(!stos.empty()) {
cout << stos.top() << endl;
stos.pop();
}
}
Upvotes: 5
Reputation: 283684
pop
doesn't return the value removed. You have to first access top()
to get the value, then call pop()
to get rid of it.
Upvotes: 0