名前空間
変種
操作

std::basic_string_view<CharT,Traits>::remove_suffix

From cppreference.com
 
 
 
 
constexpr void remove_suffix( size_type n );
(C++17以降)

ビューの末尾をn文字分だけ後ろに移動させます。

もし n > size() であった場合、動作は未定義です。

目次

[編集] パラメータ

n - ビューの末尾から削除する文字数

[編集] 戻り値

(なし)

[編集] 計算量

定数。

[編集]

#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

[編集] 関連項目

ビューの開始位置を前方に移動して縮小する
(public member function) [編集]
English 日本語 中文(简体) 中文(繁體)