std::basic_string_view::front - std::basic_string_view::front
constexpr const_reference front() const; (since C++17)
Returns reference to the first character in the view. The behavior is
undefined if
empty() == true.
reference to the first character, equivalent to
operator[](0).
// Run this code
#include <string_view>
#include <iostream>
int main() {
for (std::string_view str{"ABCDEF"}; !str.empty();
str.remove_prefix(1))
std::cout << str.front() << ' ' << str << '\n';
}
A ABCDEF
B BCDEF
C CDEF
D DEF
E EF
F F
back accesses the last character
(C++17) (public member function)
empty checks whether the view is empty
(C++17) (public member function)
front accesses the first character
(C++11) (public member function of
std::basic_string<CharT,Traits,Allocator>)