std::basic_string::begin, std::basic_string::cbegin
提供: cppreference.com
< cpp | string | basic string
iterator begin(); | ||
const_iterator begin()const; | ||
const_iterator cbegin()const; | (C++11およびそれ以降) | |
文字列の最初の文字を指すイテレータを返します。
begin()
は *this の const 性によって可変イテレータまたは定数イテレータを返します。
cbegin()
は常に定数イテレータを返します。 これは const_cast<const basic_string&>(*this).begin() と同等です。
目次 |
[編集]引数
(なし)
[編集]戻り値
最初の文字を指すイテレータ。
[編集]例外
(なし) | (C++11以前) |
noexcept 指定: noexcept | (C++11およびそれ以降) |
[編集]計算量
一定。
[編集]例
Run this code
#include <string>#include <iostream> 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) | 終端を指すイテレータを返します (パブリックメンバ関数) |