The Wayback Machine - https://web.archive.org/web/20180318113628/http://ja.cppreference.com:80/w/cpp/container/array/front
名前空間
変種
操作

std::array::front

提供: cppreference.com
< cpp‎ | container‎ | array
reference front();
(C++17以前)
constexpr reference front();
(C++17およびそれ以降)
const_reference front()const;
(C++14以前)
constexpr const_reference front()const;
(C++14およびそれ以降)

コンテナ内の最初の要素を指す参照を返します。

空のコンテナに対する front の呼び出しは未定義です。

目次

[編集]引数

(なし)

[編集]戻り値

最初の要素を指す参照。

[編集]計算量

一定。

[編集]ノート

コンテナ c に対して、式 c.front()*c.begin() と同等です。

[編集]

以下のコードは front を使用して std::array<char, 6> の最初の要素を表示します。

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

出力:

The first character is o

関連項目

最後の要素にアクセスします
(パブリックメンバ関数)[edit]
close