Пространства имён
Варианты
Действия

std::vector::front

Материал из cppreference.com

 
 
 
std::vector
Член функций
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
Элемент доступа
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)
Итераторы
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)
Потенциала
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)
Модификаторы
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
 
reference front();
const_reference front() const;
Возвращает ссылку на первый элемент в контейнере.
Original:
Returns a reference to the first element in the container.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Вызов front на пустой контейнер не определен.
Original:
Calling front on an empty container is undefined.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Содержание

[править] Параметры

(Нет)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[править] Возвращаемое значение

ссылка на первый элемент
Original:
reference to the first element
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[править] Сложность

Constant
Original:
Constant
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[править] Notes

Для контейнера c, выражение c.front() эквивалентно *c.begin().
Original:
For a container c, the expression c.front() is equivalent to *c.begin().
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[править] Пример

Следующий код использует front, чтобы отобразить первый элемент std::vector<char>
Original:
The following code uses front to display the first element of a std::vector<char>:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <vector>
#include <iostream>
 
int main()
{
    std::vector<char> letters {'o', 'm', 'g', 'w', 't', 'f'};
 
    if (!letters.empty()) {
        std::cout << "The first character is: " << letters.front() << '\n';
    }
}

Вывод:

The first character is o

See also

предоставляет доступ к последнему элементу
(public функция-член) [edit]