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

履歴 編集

function
<string_view>

std::basic_string_view::begin(C++17)

constexpr const_iterator begin() const noexcept;

概要

先頭の要素を指すイテレータを取得する。

戻り値

!empty()である場合、data()を指すイテレータを返す。そうでない場合、[begin(), end())を妥当な範囲とする未規定の値を返す。

#include <iostream>
#include <string_view>
#include <algorithm>

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

  std::for_each(sv.begin(), sv.end(), [](char c) {
    std::cout << c << std::endl;
  });
}

出力

H
e
l
l
o

バージョン

言語

  • C++17

処理系