std::basic_string<CharT,Traits,Allocator>::begin, std::basic_string<CharT,Traits,Allocator>::cbegin
: cppreference.com
<tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
| (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) | |
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) |
() |