std::vector<T,Allocator>::begin,std::vector<T,Allocator>::cbegin (3) - Linux Manuals
std::vector<T,Allocator>::begin,std::vector<T,Allocator>::cbegin: std::vector<T,Allocator>::begin,std::vector<T,Allocator>::cbegin
Command to display std::vector<T,Allocator>::begin,std::vector<T,Allocator>::cbegin
manual in Linux: $ man 3 std::vector<T,Allocator>::begin,std::vector<T,Allocator>::cbegin
NAME
std::vector<T,Allocator>::begin,std::vector<T,Allocator>::cbegin - std::vector<T,Allocator>::begin,std::vector<T,Allocator>::cbegin
Synopsis
iterator begin(); (until C++11)
iterator begin() noexcept; (since C++11)
const_iterator begin() const; (until C++11)
const_iterator begin() const noexcept; (since C++11)
const_iterator cbegin() const noexcept; (since C++11)
Returns an iterator to the first element of the container.
If the container is empty, the returned iterator will be equal to end().
range-begin-end.svg
Parameters
(none)
Return value
Iterator to the first element
Complexity
Constant
Example
// Run this code
#include <iostream>
#include <vector>
#include <string>
int main()
{
std::vector<int> ints {1, 2, 4, 8, 16};
std::vector<std::string> fruits {"orange", "apple", "raspberry"};
std::vector<char> empty;
// Sums all integers in the vector ints (if any), printing only the result.
int sum = 0;
for (auto it = ints.cbegin(); it != ints.cend(); it++)
sum += *it;
std::cout << "Sum of ints: " << sum << "\n";
// Prints the first fruit in the vector fruits, without checking if there is one.
std::cout << "First fruit: " << *fruits.begin() << "\n";
if (empty.begin() == empty.end())
std::cout << "vector 'empty' is indeed empty.\n";
}
Output:
Sum of ints: 31
First fruit: orange
vector 'empty' is indeed empty.
See also
end_ returns an iterator to the end
cend (public member function)
Pages related to std::vector<T,Allocator>::begin,std::vector<T,Allocator>::cbegin
- std::vector<T,Allocator>::back (3) - std::vector<T,Allocator>::back
- std::vector<T,Allocator>::assign (3) - std::vector<T,Allocator>::assign
- std::vector<T,Allocator>::at (3) - std::vector<T,Allocator>::at
- std::vector<T,Allocator>::capacity (3) - std::vector<T,Allocator>::capacity
- std::vector<T,Allocator>::clear (3) - std::vector<T,Allocator>::clear
- std::vector<T,Allocator>::data (3) - std::vector<T,Allocator>::data
- std::vector<T,Allocator>::emplace (3) - std::vector<T,Allocator>::emplace
- std::vector<T,Allocator>::emplace_back (3) - std::vector<T,Allocator>::emplace_back
- std::vector<T,Allocator>::empty (3) - std::vector<T,Allocator>::empty
- std::vector<T,Allocator>::end,std::vector<T,Allocator>::cend (3) - std::vector<T,Allocator>::end,std::vector<T,Allocator>::cend
- std::vector<T,Allocator>::erase (3) - std::vector<T,Allocator>::erase
- std::vector<T,Allocator>::front (3) - std::vector<T,Allocator>::front
- std::vector<T,Allocator>::get_allocator (3) - std::vector<T,Allocator>::get_allocator
- std::vector<T,Allocator>::insert (3) - std::vector<T,Allocator>::insert
- std::vector<T,Allocator>::max_size (3) - std::vector<T,Allocator>::max_size
- std::vector<T,Allocator>::operator= (3) - std::vector<T,Allocator>::operator=
- std::vector<T,Allocator>::operator[] (3) - std::vector<T,Allocator>::operator[]
- std::vector<T,Allocator>::pop_back (3) - std::vector<T,Allocator>::pop_back
- std::vector<T,Allocator>::push_back (3) - std::vector<T,Allocator>::push_back
- std::vector<T,Allocator>::rbegin,std::vector<T,Allocator>::crbegin (3) - std::vector<T,Allocator>::rbegin,std::vector<T,Allocator>::crbegin
- std::vector<T,Allocator>::rend,std::vector<T,Allocator>::crend (3) - std::vector<T,Allocator>::rend,std::vector<T,Allocator>::crend
- std::vector<T,Allocator>::reserve (3) - std::vector<T,Allocator>::reserve
- std::vector<T,Allocator>::resize (3) - std::vector<T,Allocator>::resize
- std::vector<T,Allocator>::shrink_to_fit (3) - std::vector<T,Allocator>::shrink_to_fit
- std::vector<T,Allocator>::size (3) - std::vector<T,Allocator>::size
- std::vector<T,Allocator>::swap (3) - std::vector<T,Allocator>::swap
- std::vector<T,Allocator>::vector (3) - std::vector<T,Allocator>::vector
- std::vector<T,Allocator>::~vector (3) - std::vector<T,Allocator>::~vector
- std::vector<bool,Allocator>::flip (3) - std::vector<bool,Allocator>::flip