std::basic_string_view<CharT,Traits>::back
从 zh.cppreference.net
constexpr const_reference back() const;
|
(C++17 起) | |
返回视图中最后一个字符的引用。
|
如果 empty() 为 |
,则行为未定义。 |
|
如果 empty() 为 |
(C++26 起) |
返回值
data_
[
size
(
)
-
1
]
复杂度
常量。
示例
运行此代码
#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'; }
输出:
F ABCDEF E ABCDE D ABCD C ABC B AB A A
另请参阅
|
访问首字符
(公开成员函数) |
|
|
检查视图是否为空
(公开成员函数) |
|
|
(
DR*
)
|
访问末字符
(
std::basic_string<CharT,Traits,Allocator>
的公开成员函数)
|