std::array operator[]
- since C++17
- since C++14
- until C++14
// Non const version
constexpr reference at( size_type pos );
// Const version
constexpr const_reference at( size_type pos ) const;
// Non const version
reference at( size_type pos );
// Const version
constexpr const_reference at( size_type pos ) const;
// Non const version
reference at( size_type pos );
// Const version
const_reference at( size_type pos ) const;
Returns a reference
to the character at specified indexpos
. No bounds checking is performed.
Parameters
pos
- position of the character to return
Return value
Reference to the requested character.
Exceptions
None.
Complexity
Constant.
Example
Main.cpp
#include <array>
#include <iostream>
int main()
{
std::array<int,4> numbers {2, 4, 6, 8};
std::cout << "Second element: " << numbers[1] << '\n';
numbers[0] = 5;
std::cout << "All numbers:";
for (auto i : numbers) {
std::cout << ' ' << i;
}
std::cout << '\n';
}
Output
Second element: 4
All numbers: 5 4 6 8
This article originates from this CppReference page. It was likely altered for improvements or editors' preference. Click "Edit this page" to see all changes made to this document.
Hover to see the original license.
Hover to see the original license.