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

履歴 編集

function
<string_view>

std::basic_string_view::operator[](C++17)

constexpr const_reference operator[](size_type pos) const;

概要

任意の位置の文字を取得する。

要件

戻り値

return data()[pos];

例外

投げない

備考

std::basic_string::operator[]s[s.size()]CharT()を返すが、std::basic_string_viewクラスのこの演算子では未定義動作となる

#include <cassert>
#include <string_view>

int main()
{
  std::string_view sv = "Hello World";

  char c = sv[6];
  assert(c == 'W');
}

出力

バージョン

言語

  • C++17

処理系