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

std::basic_string_view::remove_prefix

constexpr void remove_prefix(size_type n);

(since C++17)

将视图的开始向前移动n人物。

如果n > size()...

参数

n

-

number of characters to remove from the start of the view

返回值

%280%29

复杂性

常量。

二次

代码语言:javascript
复制
#include <iostream>
#include <string_view>
int main()
{
    std::string str = "   trim me";
    std::string_view v = str;
    v.remove_prefix(std::min(v.find_first_not_of(" "), v.size()));
    std::cout << "String: '" << str << "'\n"
              << "View  : '" << v << "'\n";
}

二次

产出:

二次

代码语言:javascript
复制
String: '   trim me'
View  : 'trim me'

二次

另见

remove_suffix

shrinks the view by moving its end backward (public member function)

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

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

扫码关注腾讯云开发者

领取腾讯云代金券