std::basic_string_view<CharT,Traits>::back

Returns reference to the last character in the view. The behavior is undefined if empty() == true.

# Declarations

constexpr const_reference back() const;

(since C++17)

# Return value

Reference to the last character, equivalent to operator[](size() - 1).

# Example

#include <iostream>
#include <string_view>
 
int main()
{
    for (std::string_view str{"ABCDEF"}; !str.empty(); str.remove_suffix(1))
        std::cout << str.back() << ' ' << str << '\n';
}

# See also