命名空间
变体
操作

std::experimental::basic_string_view<CharT,Traits>::remove_suffix

来自 cppreference.cn
 
 
实验性
技术规范
Filesystem library (filesystem TS)
Library fundamentals (library fundamentals TS)
Library fundamentals 2 (library fundamentals TS v2)
Library fundamentals 3 (library fundamentals TS v3)
Extensions for parallelism (parallelism TS)
Extensions for parallelism 2 (parallelism TS v2)
Extensions for concurrency (concurrency TS)
Extensions for concurrency 2 (concurrency TS v2)
Concepts (concepts TS)
Ranges (ranges TS)
Reflection (reflection TS)
Mathematical special functions (special functions TR)
实验性 非TS
模式匹配
线性代数
std::execution
合约
2D 图形
 
 
 
constexpr void remove_suffix( size_type n );
(library fundamentals TS)

将视图的末尾向后移动 n 个字符。

如果 n > size(),则行为未定义。

目录

[edit] 参数

n - 从视图末尾移除的字符数

[edit] 返回值

(无)

[edit] 复杂度

常数。

[edit] 示例

#include <experimental/string_view>
#include <iostream>
 
int main()
{
    char arr[] = {'a', 'b', 'c', 'd', '\0', '\0', '\0'};
    std::experimental::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

[edit] 参见

通过向前移动其起始位置来缩小视图
(public member function) [edit]