名前空間
変種
操作

std::basic_string<CharT,Traits,Allocator>::front

提供: cppreference.com
< cpp‎ | string‎ | basic string
 
 
 
std::basic_string
 
CharT& front();
(C++11以上)
(C++20未満)
constexpr CharT& front();
(C++20以上)
const CharT& front() const;
(C++11以上)
(C++20未満)
constexpr const CharT& front() const;
(C++20以上)

文字列の最初の文字を指す参照を返します。 empty() == true の場合、動作は未定義です。

目次

[編集] 引数

(なし)

[編集] 戻り値

最初の文字を指す参照。 operator[](0) と同等。

[編集] 計算量

一定。

[編集]

#include <iostream>
#include <string>
 
int main()
{
  {
    std::string s("Exemplary");
    char& f = s.front();
    f = 'e';
    std::cout << s << '\n'; // "exemplary"
  }
 
  {
    std::string const c("Exemplary");
    char const& f = c.front();
    std::cout << &f << '\n'; // "Exemplary"
  }
}

出力:

exemplary
Exemplary

[編集] 関連項目

(C++11)
最後の文字にアクセスします
(パブリックメンバ関数) [edit]