Article ID: 158086
Article Last Modified on 1/9/2006
<list>
reference back(); const_reference back() const; reference front(); const_reference front() const; void pop_back(); void pop_front(); void push_back(const T& x); void push_front(const T& x);Note The class/parameter names in the prototype may not match the version in the header file. Some have been modified to improve readability.
//////////////////////////////////////////////////////////////////////
//
// Compile options needed: -GX
//
// liststck.cpp : This example shows how to use the various stack
// like functions of list.
//
// Functions:
//
// list::back
// list::front
// list::pop_back
// list::pop_front
// list::push_back
// list::push_front
//
// Written by Andrew Bradnan
// Copyright (c) 1996 Microsoft Corporation. All rights reserved.
//////////////////////////////////////////////////////////////////////
#include <list>
#include <string>
#include <iostream>
using namespace std;
#if _MSC_VER > 1020 // if VC++ version is > 4.2
using namespace std; // std c++ libs implemented in std
#endif
typedef list<string, allocator<string> > LISTSTR;
void main()
{
LISTSTR test;
test.push_back("back");
test.push_front("middle");
test.push_front("front");
// front
cout << test.front() << endl;
// back
cout << test.back() << endl;
test.pop_front();
test.pop_back();
// middle
cout << test.front() << endl;
}
The Program Output is: front back middle
Additional query words: STL STLSample kbdss list::back list::front list::pop_back list::pop_front list::push_back list::push_front
Keywords: kbhowto kbinfo kbcode KB158086