Skip to content

Latest commit

 

History

History
50 lines (37 loc) · 964 Bytes

back.md

File metadata and controls

50 lines (37 loc) · 964 Bytes

back

  • string[meta header]
  • std[meta namespace]
  • basic_string[meta class]
  • function[meta id-type]
  • cpp11[meta cpp]
const charT& back() const;           // (1) C++11
constexpr const charT& back() const; // (1) C++20

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

概要

末尾要素への参照を取得する。

要件

!empty()

戻り値

operator[](size() - 1) の結果を返す。

#include <iostream>
#include <string>

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

  char& c = s.back();
  std::cout << c << std::endl;
}
  • back()[color ff0000]

出力

o

参照