std::basic_string_view<CharT,Traits>::remove_suffix
提供: cppreference.com
< cpp | string | basic string view
constexprvoid remove_suffix(size_type n); | (C++17以上) | |
ビューの終了位置を n
文字だけ後退させます。
n > size() の場合、動作は未定義です。
目次 |
[編集]引数
n | - | ビューの終端から削除する文字数 |
[編集]戻り値
(なし)
[編集]計算量
一定。
[編集]例
Run this code
#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
[編集]関連項目
始点を前進させることによってビューを縮小させます (パブリックメンバ関数) |