1: //queue04.cpp
3: #include <iostream>
4: #include <queue>
5: using namespace std;
7: int main()
8: {
9: cout << "\nThis program illustrates how *not* to access the "
10: "components of a queue.";
11: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
13: queue<char> q;
14: q.push('A');
15: q.push('B');
16: q.push('C');
17: q.push('D');
19: cout << "\nThe queue q contains " << q.size() << " values.";
20: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
22: cout << "\nNow we attempt to display the values in the queue "
23: "using a for-loop and\nchecking the size of the queue to "
24: "determine when to stop.";
25: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
27: cout << "\nHere they are, in \"FIFO\" order:\n";
28: for (queue<int>::size_type i=1; i<=q.size(); i++) //Whoops!
29: {
30: cout << "Popping: ";
31: cout << q.front() << "\n";
32: q.pop();
33: }
34: cout << "Press Enter to continue ... "; cin.ignore(80, '\n');
35: }