std::basic_string::begin,(3)
π std::basic_string::begin,(3) π
okay so bestie, we're reading the C++ Standard Libary manual page for std::basic_string::begin,(3) β yes, that exact title, comma and all, she's quirky like that. This is the group chat where begin() and cbegin() get explained, and honestly? iconic. π«Ά
πΈ NAME πΈ
std::basic_string::begin, β and the original NAME line literally has std::basic_string::begin, - std::basic_string::begin,, so we're keeping both appearances because details are sacred. periodt. π
β¨ Synopsis β¨
iterator begin(); (1) (noexcept since C++11)
(constexpr since C++20)
const_iterator begin() const; (2) (noexcept since C++11)
(constexpr since C++20)
const_iterator cbegin() const noexcept; (3) (since C++11)
(constexpr since C++20)
It returns an iterator to the first character of the string. main character energy, genuinely. π
begin() returns a mutable or constant iterator, depending on the constness of *this. So the constness of *this is doing the vibe check here. π
cbegin() always returns a constant iterator. It is equivalent to const_cast<const basic_string&>(*this).begin() β yes, that's the exact equivalence, no cap. πͺ
There's also a diagram situation named range-begin-end.svg, so picture the range begin/end visual there, bestie. π¦
π Parameters π
None. Zero. (none). Not a single argument. π
β Return value β
Iterator to the first character. That's the whole return, and she ate. π
π₯ Complexity π₯
Constant.
π Notes π
libc++ backports cbegin() to C++98 mode. cute of her, fr fr. π
π Example π
// Run this code
#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
}
πΈ Output πΈ
exemplar
e
π§ See also π§
endβ returns an iterator to the endcendβ (public member function) (C++11)beginβ returns an iterator to the beginningcbeginβ (public member function ofstd::basic_string_view<CharT,Traits>)
source: http://cppreference.com Β· version/date: 2024.06.10 Β· page: std::basic_string::begin,(3) β okay that's the whole manual page, bestie, go forth and iterator π
β¨π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms