std::basic_string::back(3)
πΈ NAME πΈ
Hiii bestie π welcome to std::basic_string::back(3), straight outta the C++ Standard Libary. The name is literally std::basic_string::back β and yeah, itβs also std::basic_string::back, iconic behavior.
β¨ Synopsis β¨
CharT& back(); (1) (constexpr since C++20)
const CharT& back() const; (2) (constexpr since C++20)
Returns a reference to the last character in the string. The behavior is undefined if empty() is true β like, do not do that, bestie ππ.
π Parameters π
- (none) β literally no parameters, she takes nothing.
π Return value π
Reference to the last character, equivalent to operator[](size() - 1). Slay.
π¦ Complexity π¦
Constant. No cap.
πΈ Notes πΈ
In libstdc++, back() is not available in C++98 mode. Periodt.
π₯ Example π₯
// Run this code
#include <iostream>
#include <string>
int main()
{
std::string s("Exemplary");
char& back1 = s.back();
back1 = 's';
std::cout << s << '\n'; // "Exemplars"
std::string const c("Exemplary");
char const& back2 = c.back();
std::cout << back2 << '\n'; // 'y'
}
π Output π
Exemplars
y
π Defect reports π
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
- DR:
LWG 534Β· Applied to:C++98Β· Behavior as published:std::basic_stringdid not have the member functionback()Β· Correct behavior: added
π See also π
frontβ accesses the first character (DR*) (public member function)backβ accesses the last character (public member function ofstd::basic_string_view<CharT,Traits>)
http://cppreference.com Β· 2024.06.10 Β· std::basic_string::back(3) β bye bestie, go slay your strings π
β¨π«Ά
π¦ 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