次の方法で共有


deque::operator[]

指定した位置に deque 要素への参照を返します。

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

パラメーター

  • _Pos
    参照される deque の要素の位置。

戻り値

位置が引数で指定された要素への参照。 指定された位置が deque のサイズを超える場合、結果は未定義になります。

解説

operator[] の戻り値が const_referenceに割り当てると、deque オブジェクトは変更できません。 operator[] の戻り値が リファレンスに割り当てると、deque オブジェクトを変更できます。

_SECURE_SCL 1 でコンパイルするとランタイム エラーは deque の境界の外に要素にアクセスしようとすると発生します。詳細については、「チェックを行う反復子」を参照してください。

使用例

// 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;
   
}
  

必要条件

ヘッダー: <deque>

名前空間: std

参照

関連項目

deque クラス

deque::operator[] と deque::at

標準テンプレート ライブラリ