Stack simple question

Are stacks deleted when they are removed from the top? I'm just wondering
oh its ok, I just found out. The reason is in this code, apparently its true

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
// Read words and print them in reverse order.
//   Variation using stack and string.
// Fred Swartz 2001-11-08, 2001-12-04

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

int main() {

    stack<string> allwords; // stack of all words
    string word;            // input buffer for words.

    // read words/tokens from input stream
	int u = 0;
    while (u < 5) {
		cin >> word;
        allwords.push(word);
		u++;
    }
    
    cout << "Number of words = " << allwords.size() << endl;

    // write out all the words in reverse order.
    while (!allwords.empty()) {
       cout << allwords.top() << endl;
       allwords.pop();            // remove top element
    }
	cin.get();
    return 0;
}//end main 
Topic archived. No new replies allowed.