public member function
<vector>
std::vector::atreference at (size_type n);const_reference at (size_type n) const;
Access element
Returns a reference to the element at position n in the vector.The function automatically checks whether n is within the bounds of valid elements in the vector, throwing an out_of_range exception if it is not (i.e., if n is greater than, or equal to, its size). This is in contrast with member operator[], that does not check against bounds.
If the vector object is const-qualified, the function returns a const_reference. Otherwise, it returns a reference.
Member types reference and const_reference are the reference types to the elements of the container (see vector member types).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// vector::at
#include <iostream>
#include <vector>
int main ()
{
std::vector<int> myvector (10); // 10 zero-initialized ints
// assign some values:
for (unsigned i=0; i<myvector.size(); i++)
myvector.at(i)=i;
std::cout << "myvector contains:";
for (unsigned i=0; i<myvector.size(); i++)
std::cout << ' ' << myvector.at(i);
std::cout << '\n';
return 0;
}
myvector contains: 0 1 2 3 4 5 6 7 8 9
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.3