std::string_view remove_prefix() 方法
- 自 C++17 起
// 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'