std::basic_string<CharT,Traits,Allocator>::begin, std::basic_string<CharT,Traits,Allocator>::cbegin
iterator begin(); | (1) |
(noexcept с C++11) (constexpr с C++20) |
const_iterator begin() const; | (2) |
(noexcept с C++11) (constexpr с C++20) |
const_iterator cbegin() const noexcept; | (3) |
(начиная с C++11) (constexpr с C++20) |
Возвращает итератор на первый символ строки.
begin() возвращает изменяемый или константный итератор в зависимости от константности *this.
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>) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/string/basic_string/begin