std::basic_string<CharT,Traits,Allocator>::begin, std::basic_string<CharT,Traits,Allocator>::cbegin
提供: cppreference.com
< cpp | string | 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() と同等です。
目次 |
[編集] 引数
(なし)
[編集] 戻り値
最初の文字を指すイテレータ。
[編集] 計算量
一定。
[編集] 例
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) |
終端を指すイテレータを返します (パブリックメンバ関数) |