Use subscript operator to modify element in deque at location 1 - C++ STL

C++ examples for STL:deque

Description

Use subscript operator to modify element in deque at location 1

Demo Code

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

int main() //w w w .j a v a  2  s. c  om
{ 
    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 ); 

    // use subscript operator to modify element at location 1 
    values[ 1 ] = 5.4; 
    cout << "\nAfter values[ 1 ] = 5.4, values contains: "; 
    copy( values.begin(), values.end(), output ); 
    cout << endl; 
}

Result


Related Tutorials