std::begin
From Cppreference
C++ Standard Library |
---|
Iterator library |
Defined in header <iterator>
|
||
template< class C >
auto begin( C& c ) -> decltype(c.begin()); |
(1) | (C++11 feature) |
template< class C >
auto begin( const C& c ) -> decltype(c.begin()); |
(2) | (C++11 feature) |
template< class T, size_t N >
T* begin( T (&array)[N] ); |
(3) | (C++11 feature) |
Returns an iterator to the beginning of the given container c or array array.
Contents |
[edit] Parameters
c | - | a container with a begin method |
array | - | an array of arbitrary type |
[edit] Return value
an iterator to the beginning of c or array
[edit] Example
#include <iostream> #include <vector> #include <iterator> int main() { std::vector<int> v = { 3, 1, 4 }; auto vi = std::begin(v); std::cout << *vi << '\n'; int a[] = { -5, 10, 15 }; auto ai = std::begin(a); std::cout << *ai << '\n'; }
Output:
3 -5
[edit] See also
|
returns an iterator to the end of a container or array (function) |