Add value to deque and loop through all element - C++ STL

C++ examples for STL:deque

Description

Add value to deque and loop through all element

Demo Code

#include <iostream> 
#include <deque> // deque class-template definition 
#include <algorithm> // copy algorithm 
#include <iterator> // ostream_iterator 
using namespace std; 

int main() //from ww  w .  j  av a  2  s.  co  m
{ 
    deque< double > values; // create deque of doubles 
    ostream_iterator< double > output( cout, " " ); 

    // insert elements in values 
    values.push_front( 2.2 ); 
    values.push_front( 3.5 ); 
    values.push_back( 1.1 ); 

    cout << "values contains: "; 

    // use subscript operator to obtain elements of values 
    for ( unsigned int i = 0; i < values.size(); ++i ) 
       cout << values[ i ] << ' '; 

}

Result


Related Tutorials