◐ Shell
clean mode source ↗

std::array<T,N>::front - cppreference.com

提供: cppreference.com

<tbody> </tbody> <tbody class="t-dcl-rev "> </tbody><tbody> </tbody> <tbody class="t-dcl-rev "> </tbody><tbody> </tbody>

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';
    }  
}

出力:

関連項目