Namespace
Varianti

std::vector::begin, std::vector::cbegin

Da cppreference.com.
< cpp‎ | container‎ | vector
 
 
 
std::vector
Membri funzioni
Original:
Member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
vector::vector
vector::~vector
vector::operator=
vector::assign
vector::get_allocator
Elemento accesso
Original:
Element access
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
vector::at
vector::operator[]
vector::front
vector::back
vector::data(C++11)
Iteratori
Original:
Iterators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
vector::begin
vector::cbegin

(C++11)
vector::end
vector::cend

(C++11)
vector::rbegin
vector::crbegin

(C++11)
vector::rend
vector::crend

(C++11)
Capacità
Original:
Capacity
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
vector::empty
vector::size
vector::max_size
vector::reserve
vector::capacity
vector::shrink_to_fit(C++11)
Modificatori
Original:
Modifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
vector::clear
vector::insert
vector::emplace(C++11)
vector::erase
vector::push_back
vector::emplace_back(C++11)
vector::pop_back
vector::resize
vector::swap
 
iterator begin();
(fino al c++11)
iterator begin() noexcept;
(dal C++11)
const_iterator begin() const;
(fino al c++11)
const_iterator begin() const noexcept;
(dal C++11)
const_iterator cbegin() const noexcept;

Restituisce un iteratore al primo elemento del container.

Se il container è vuoto, l'iteratore restituito sarà uguale a end().

range-begin-end.svg

Indice

[modifica] Parametri

(nessuno)

[modifica] Valore restituito

Iteratore al primo elemento

[modifica] Complessità

Costante


[modifica] Example

#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.

[modifica] Vedi anche

restituisce un iteratore fino alla fine
Original:
returns an iterator to the end
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(metodo pubblico) [modifica]