跳到主要内容

std::string_view remove_prefix() 方法

// Const version only
constexpr void remove_prefix( size_type n );

将视图的起始位置向前移动 n 个字符。

未定义行为

行为未定义

如果 n > size()

参数

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

返回值

(无)

复杂度

常数 - O(1)

示例

Main.cpp
#include <iostream>
#include <algorithm>
#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";
}
可能输出
String: '   trim me'
View : 'trim me'
本文来自此 CppReference 页面。它可能经过了修改以进行改进或满足编辑偏好。点击“编辑此页面”查看本文档的所有更改。
悬停查看原始许可证。

std::string_view remove_prefix() 方法

// Const version only
constexpr void remove_prefix( size_type n );

将视图的起始位置向前移动 n 个字符。

未定义行为

行为未定义

如果 n > size()

参数

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

返回值

(无)

复杂度

常数 - O(1)

示例

Main.cpp
#include <iostream>
#include <algorithm>
#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";
}
可能输出
String: '   trim me'
View : 'trim me'
本文来自此 CppReference 页面。它可能经过了修改以进行改进或满足编辑偏好。点击“编辑此页面”查看本文档的所有更改。
悬停查看原始许可证。