array::operator[]
更新 : 2007 年 11 月
指定した位置にある要素にアクセスします。
reference operator[](size_type off);
const_reference operator[](size_type off) const;
パラメータ
- off
アクセスする要素の位置。
解説
このメンバ関数は、off の位置にある、被制御シーケンスの要素への参照を返します。この位置が無効であった場合の動作は未定義です。
使用例
// std_tr1__array__array_operator_sub.cpp
// compile with: /EHsc
#include <array>
#include <iostream>
typedef std::tr1::array<int, 4> Myarray;
int main()
{
Myarray c0 = {0, 1, 2, 3};
// display contents " 0 1 2 3"
for (Myarray::const_iterator it = c0.begin();
it != c0.end(); ++it)
std::cout << " " << *it;
std::cout << std::endl;
// display odd elements " 1 3"
std::cout << " " << c0[1];
std::cout << " " << c0[3];
std::cout << std::endl;
return (0);
}
0 1 2 3
1 3
必要条件
ヘッダー : <array>
名前空間 : std::tr1