C++ STL deque, assign() program 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:
To do: Using the C++ assign() to erase elements from a deque and copies a new set of elements to the target deque in C++ programming
To show: How to use the deque, assign() to erase elements from a deque and copies a new set of elements to the target deque in C++ programming
// C++ STL deque, assign
#include <deque>
#include <iostream>
using namespace std;
int main(void)
{
// deque containers
deque <int> con1, con2;
// deque iterator
deque <int>::const_iterator cIter;
// push/insert data
con1.push_back(10);
con1.push_back(9);
con1.push_back(13);
con2.push_back(41);
con2.push_back(25);
con2.push_back(36);
// print the data and do some operations
cout<<"con1 deque: ";
for (cIter = con1.begin(); cIter != con1.end(); cIter++)
cout<<" "<<*cIter;
cout<<endl;
cout<<"\nOperation: con1.assign(++con2.begin(), con2.end())"<<endl;
con1.assign(++con2.begin(), con2.end());
cout<<"con1 deque: ";
for (cIter = con1.begin(); cIter != con1.end(); cIter++)
cout<<" "<<*cIter;
cout<<endl;
cout<<"\nOperation: con1.assign(7, 4)"<<endl;
con1.assign(7, 4);
cout<<"con1 deque: ";
for (cIter = con1.begin(); cIter != con1.end(); cIter++)
cout<<" "<<*cIter;
cout<<endl;
return 0;
}
Output examples:
con1 deque: 10 9 13
Operation: con1.assign(++con2.begin(), con2.end())
con1 deque: 25 36
Operation: con1.assign(7, 4)
con1 deque: 4 4 4 4 4 4 4
Press any key to continue . . .