std::array::front

来自cppreference.com
 
 
 
std::array
成员函数
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.
元素的访问
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.
array::at
array::operator[]
array::front
array::back
array::data
迭代器
Original:
Iterators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
array::begin
array::cbegin
array::end
array::cend
array::rbegin
array::crbegin
array::rend
array::crend
容量
Original:
Capacity
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
array::empty
array::size
array::max_size
修饰符
Original:
Modifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
array::fill
array::swap
非成员函数
Original:
Non-member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
get
swap
Helper类
Original:
Helper classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
tuple_size
tuple_element
 
reference front();
(因为C + +11)
const_reference front() const;
(因为C + +11)
返回的第一个元素在容器中.
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.

[编辑] 复杂性

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

[编辑] 注释

对于一个容器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::array<char>
Original:
The following code uses front to display the first element of a std::array<char>:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

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

Output:

The first character is o

See also

access the last element
(公共成员函数) [edit]