std::basic_string_view<CharT,Traits>:: remove_suffix
|
constexpr
void
remove_suffix
(
size_type n
)
;
|
(C++17 起) | |
将视图的末尾向后移动 n 个字符。
|
若 n > size ( ) 为 true ,则行为未定义。 |
(C++26 前) |
|
若 n > size ( ) 为 true : |
(C++26 起) |
目录 |
参数
| n | - | 要从视图末尾移除的字符数量 |
复杂度
常量。
示例
#include <iostream> #include <string_view> int main() { char arr[] = {'a', 'b', 'c', 'd', '\0', '\0', '\0'}; std::string_view v(arr, sizeof arr); auto trim_pos = v.find('\0'); if (trim_pos != v.npos) v.remove_suffix(v.size() - trim_pos); std::cout << "Array: '" << arr << "', size=" << sizeof arr << '\n' << "View : '" << v << "', size=" << v.size() << '\n'; }
输出:
Array: 'abcd', size=7 View : 'abcd', size=4
参见
|
通过将起始位置前移来缩小视图范围
(公开成员函数) |