Code /* * TestContainers.cpp * demonstration usage of deque, stack, and map * CIS 250 * David Klick * 2009-03-30 * */ #include #include #include #include #include using std::cout; using std::deque; using std::map; using std::stack; using std::string; int main() { int i; cout << "\nPlaying with a queue (adding 1..10)"; deque myQueue; for (i=1; i<11; i++) myQueue.push_back(i); cout << "\nContents: "; for (i=0; i myStack; for (i=1; i<11; i++) myStack.push(i); cout << "\nRemoving items from the stack: "; while (!myStack.empty()) { cout << myStack.top() << ", "; myStack.pop(); } cout << "\n\nPlaying with a map (adding 1..10 and names)"; map myMap; myMap[1] = string("one"); myMap[2] = string("two"); myMap[3] = string("three"); myMap[4] = string("four"); myMap[5] = string("five"); myMap[6] = string("six"); myMap[7] = string("seven"); myMap[8] = string("eight"); myMap[9] = string("nine"); myMap[10] = string("ten"); cout << "\nFinding items in the map:\n"; for (i=0; i<12; i++) { if (myMap.count(i) == 0) cout << "No match found for " << i << '\n'; else cout << i << " matches " << myMap[i] << '\n'; } cout << '\n'; system("pause"); return 0; }