The Wayback Machine - https://web.archive.org/web/20180513132108/http://ja.cppreference.com:80/w/cpp/string/basic_string/begin
名前空間
変種
操作

std::basic_string::begin, std::basic_string::cbegin

提供: cppreference.com
< cpp‎ | string‎ | basic string
 
 
 
std::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() と同等です。

range-begin-end.svg

目次

[編集]引数

(なし)

[編集]戻り値

最初の文字を指すイテレータ。

[編集]例外

(なし)(C++11以前)
noexcept 指定:  
noexcept
  
(C++11およびそれ以降)

[編集]計算量

一定。

[編集]

#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)
終端を指すイテレータを返します
(パブリックメンバ関数)[edit]
close