次の方法で共有


array::at

Accesses an element at a specified position.

reference at(size_type off);
const_reference at(size_type off) const;

Parameters

  • off
    Position of element to access.

Remarks

The member functions return a reference to the element of the controlled sequence at position off. If that position is invalid, the function throws an object of class out_of_range.

Example

 

// std__array__array_at.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.at(1); 
    std::cout << " " << c0.at(3); 
    std::cout << std::endl; 
 
    return (0); 
    } 
 

Requirements

Header: <array>

Namespace: std

See Also

Reference

<array>

array Class (TR1)

array::operator[]

Other Resources

<array> Members