const_iterator cbegin() const noexcept; // (1) C++11
constexpr const_iterator cbegin() const noexcept; // (1) C++20
概要
文字列の先頭を指す読み取り専用イテレータを取得する。
戻り値
先頭を指す読み取り専用イテレータ。
例外
投げない
例
#include <iostream>
#include <string>
int main()
{
std::string s = "hello";
// 先頭へのイテレータを取得
decltype(s)::const_iterator it = s.cbegin();
// イテレータが指している要素を参照
const char& c = *it;
std::cout << c << std::endl;
}
出力
h
参照
- P0980R1 Making
std::stringconstexpr - LWG Issue 1192.
basic_stringmissing definitions for cbegin / cend / crbegin / crend- C++11で、これらのメンバ関数が追加された。ほかのコンテナには追加されていたが、
basic_stringには記載が漏れていた
- C++11で、これらのメンバ関数が追加された。ほかのコンテナには追加されていたが、