最終更新日時(UTC):
が更新

履歴 編集

function
<string>

std::basic_string::front(C++11)

const charT& front() const;           // (1) C++11
constexpr const charT& front() const; // (1) C++20

charT& front();                       // (2) C++11
constexpr charT& front();             // (2) C++20

概要

先頭要素への参照を返す。

要件

!empty()

戻り値

operator[](0) の結果を返す。

#include <iostream>
#include <string>

int main()
{
  std::string s = "hello";

  char& c = s.front();
  std::cout << c << std::endl;
}

出力

h

参照