Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Visual Studio
Visual C++
Header Files
<deque>
<deque> Classes
deque Class
deque Operators
 deque::operator[]

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Visual C++ Standard Library
deque::operator[]

Returns a reference to the deque element at a specified position.

reference operator[](
   size_type _Pos
);
const_reference operator[](
   size_type _Pos
) const;
_Pos

The position of the deque element to be referenced.

A reference to the element whose position is specified in the argument. If the position specified is greater than the size of the deque, the result is undefined.

If the return value of operator[] is assigned to a const_reference, the deque object cannot be modified. If the return value of operator[] is assigned to a reference, the deque object can be modified.

When compiling with _SECURE_SCL 1, a runtime error will occur if you attempt to access an element outside the bounds of the deque. See Checked Iterators for more information.

// deque_op_ref.cpp
// compile with: /EHsc
#include <deque>
#include <iostream>

int main( ) 
{
   using namespace std;
   deque <int> c1;

   c1.push_back( 10 );
   c1.push_back( 20 );
   cout << "The first integer of c1 is " << c1[0] << endl;
   int& i = c1[1];
   cout << "The second integer of c1 is " << i << endl;
   
}
The first integer of c1 is 10
The second integer of c1 is 20

Header: <deque>

Namespace: std

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker