C++ STL  deque, back() 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++ back() to return a reference to the last element of the deque in C++ programming

To show: How to use the C++ deque, back() to return a reference to the last element of the deque in C++ programming

 

// C++ STL deque, back()

#include <deque>

#include <iostream>

using namespace std;

 

int main(void)

{

// deque container

deque <int> con1;

 

// push/insert data

con1.push_back(21);

con1.push_back(32);

con1.push_back(9);

con1.push_back(17);

 

int& i = con1.back();

const int& ii = con1.front();

cout<<"The last integer of con1 deque is " <<i<<endl;

i--;

cout<<"The next-to-last integer of con1 deque is "<<ii<<endl;

return 0;

}

 

Output examples:

 

The last integer of con1 deque is 17

The next-to-last integer of con1 deque is 21

Press any key to continue . . .

 

 

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