deque::operator
會傳回位於指定位置在 deque 項目的參考。
reference operator[](
size_type _Pos
);
const_reference operator[](
size_type _Pos
) const;
參數
- _Pos
要參考的 deque 項目的位置。
傳回值
在位置在引數中指定之項目的參考。如果指定的位置、deque 的大小,則結果會是未定義。
備註
如果 operator[] 的傳回值指派給 const_reference,無法修改 deque 物件。如果 operator[] 的傳回值指派給 reference,可以修改 deque 物件。
當以 _SECURE_SCL 1 編譯時,執行時會發生錯誤,如果您嘗試存取 deque 界限之外的項目。如需詳細資訊,請參閱檢查過的 Iterator。
範例
// 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