名前空間
変種
操作

std::basic_string<CharT,Traits,Allocator>::begin, std::basic_string<CharT,Traits,Allocator>::cbegin

提供: cppreference.com
< cpp‎ | string‎ | basic string
2020年2月18日 (火) 04:47時点におけるFruderica (トーク | 投稿記録)による版

(差分) ←前の版 | 最新版 (差分) | 次の版→ (差分)
 
 
 
std::basic_string
 
(1)
iterator begin();
(C++11未満)
iterator begin() noexcept;
(C++11以上)
(C++20未満)
constexpr iterator begin() noexcept;
(C++20以上)
(2)
const_iterator begin() const;
(C++11未満)
const_iterator begin() const noexcept;
(C++11以上)
(C++20未満)
constexpr const_iterator begin() const noexcept;
(C++20以上)
(3)
const_iterator cbegin() const noexcept;
(C++11以上)
(C++20未満)
constexpr const_iterator cbegin() const noexcept;
(C++20以上)

文字列の最初の文字を指すイテレータを返します。

begin()*this の const 性によって可変イテレータまたは定数イテレータを返します。

cbegin() は常に定数イテレータを返します。 これは const_cast<const basic_string&>(*this).begin() と同等です。

range-begin-end.svg

目次

[編集] 引数

(なし)

[編集] 戻り値

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

[編集] 計算量

一定。

[編集]

#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]