std::basic_string::back
De cppreference.com
< cpp | string | basic string
CharT& back(); |
(depuis C++11) | |
const CharT& back() const; |
(depuis C++11) | |
Retourne une référence au dernier carcatère de la chaîne. Le comportement est indéfini si empty() == true.
Sommaire |
[modifier] Paramètres
(aucun)
[modifier] Valeur de retour
référence au dernier carcatère, équivalent à operator[](size() - 1).
[modifier] Complexity
Constante
[modifier] Example
#include <iostream> #include <string> int main() { { std::string s("Exemplary"); char& back = s.back(); back = 's'; std::cout << s << '\n'; // "Exemplars" } { std::string const c("Exemplary"); char const& back = c.back(); std::cout << back << '\n'; // 'y' } }
Résultat :
Exemplars y
[modifier] Voir aussi
(C++11) |
accède au premier caractère (fonction membre publique) |