std::basic_string<CharT,Traits,Allocator>::begin, std::basic_string<CharT,Traits,Allocator>::cbegin
ja.cppreference.net より
iterator begin();
|
(1) | (C++11 から noexcept) (C++20 から constexpr) |
const_iterator begin() const;
|
(2) | (C++11 から noexcept) (C++20 から constexpr) |
const_iterator cbegin() const noexcept;
|
(3) | (C++11 以上) (C++20 から constexpr) |
文字列の最初の文字を指すイテレータを返します。
begin() は、変更可能または 定数イテレータを返します。これは *this のconst性に依存します。
cbegin() は常に 定数イテレータを返します。これは const_cast<const basic_string&>(*this).begin() と同等です。
パラメータ
(なし)
戻り値
最初の文字へのイテレータ。
計算量
定数。
注記
libc++は
cbegin()
をC++98モードにバックポートします。
例
このコードを実行
#include <iostream> #include <string> int main() { std::string s("Exemplar"); *s.begin() = 'e'; std::cout << s << '\n'; auto i = s.cbegin(); std::cout << *i << '\n'; // *i = 'E'; // error: i is a constant iterator }
出力:
exemplar e
関連項目
|
(C++11)
|
終端へのイテレータを返す
(公開メンバ関数) |
|
先頭へのイテレータを返す
( std::basic_string_view<CharT,Traits>の公開メンバ関数)
|