C++ STL, the list program example

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Header file: Standard

Additional library: none/default

Additional project setting: Set project to be compiled as C++

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)

Other info: none

To do: Defining the container template class list and several supporting templates in C++ programming

To show: How to use the list to define the container template class list and several supporting templates in C++ programming

 

// C++ STL list example

#include <iostream>

#include <list>

using namespace std;

 

int main(void)

{

// list container for character elements

list<char> elem;

char chs;

 

cout<<"elem list is: ";

// append elements from 'a' to 'z'

for(chs = 'a'; chs <= 'z'; ++chs)

elem.push_back(chs);

// while there are elements, print and remove the element

while(!elem.empty())

{

cout<<elem.front()<<' ';

elem.pop_front();

}

cout<<endl;

return 0;

}

 

Output examples:

 

elem list is: a b c d e f g h i j k l m n o p q r s t u v w x y z

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index