array::operator[]

访问元素中的指定位置。

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::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); 
    } 
 
  

要求

数组页眉: <>

命名空间: std

请参见

参考

<array>

array 类 (STL)

array::at