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
复杂性
常量。
例
二次
#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';
}
二次
产出:
二次
Array: 'abcd', size=7
View : 'abcd', size=4
二次
另见
remove_prefix | shrinks the view by moving its start forward (public member function) |
---|
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
http://en.cppreference.com/w/cpp/string/basic[医]弦[医]查看/删除[医]后缀