C++ STL  insert_iterator::container_type code example

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Header file: Standard

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: Using the C++ which is a type that represents the container into which a general insertion is to be made in C++ programming

To show: How to use the C++ container_type of the insert_iterator or a template class which is a type that represents the container into which a general insertion is to be made in C++ programming

 

// C++ STL insert_iterator, container_type

#include <iterator>

#include <list>

#include <iostream>

using namespace std;

 

int main(void)

{

// list container

list<int> lst1;

// iterator

list<int>::iterator veciter;

insert_iterator<list<int> >::container_type lst2 = lst1;

 

// insert/push data

inserter(lst2, lst2.end()) = 12;

inserter(lst2, lst2.end()) = 17;

inserter(lst2, lst2.begin()) = 24;

inserter(lst2, lst2.begin()) = 9;

 

// print the data

cout<<"The lst2 list data: ";

for(veciter = lst2.begin(); veciter != lst2.end(); veciter++)

cout<<*veciter<<" ";

cout<<endl;

return 0;

}

 

Output examples:

 

The lst2 list data: 9 24 12 17

Press any key to continue . . .

 

 

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