首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::basic_string_view::remove_suffix

constexpr void remove_suffix(size_type n);

(since C++17)

将视图的末尾移回n人物。

如果n > size()...

参数

n

-

number of characters to remove from the end of the view

返回值

%280%29

复杂性

常量。

二次

代码语言:javascript
复制
#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';
}

二次

产出:

二次

代码语言:javascript
复制
Array: 'abcd', size=7
View : 'abcd', size=4

二次

另见

remove_prefix

shrinks the view by moving its start forward (public member function)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券