名稱空間
變體
操作

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

來自 cppreference.com
 
 
實驗性
技術規範
檔案系統庫 (檔案系統 TS)
庫基礎 (庫基礎 TS)
庫基礎 2 (庫基礎 TS v2)
庫基礎 3 (庫基礎 TS v3)
並行性擴充套件 (並行性 TS)
並行性擴充套件 2 (並行性 TS v2)
併發性擴充套件 (併發性 TS)
併發擴充套件 2 (concurrency TS v2)
概念 (概念 TS)
範圍 (範圍 TS)
反射 (反射 TS)
數學特殊函式 (特殊函式 TR)
實驗性非 TS
模式匹配
線性代數
std::execution
契約
2D 圖形
 
 
 
constexpr void remove_suffix( size_type n );
(庫基礎 TS)

將檢視的末尾向後移動 n 個字元。

如果 n > size(),則行為未定義。

目錄

[編輯] 引數

n - 從檢視末尾移除的字元數

[編輯] 返回值

(無)

[編輯] 複雜度

常數時間。

[編輯] 示例

#include <experimental/string_view>
#include <iostream>
 
int main()
{
    char arr[] = {'a', 'b', 'c', 'd', '\0', '\0', '\0'};
    std::experimental::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) [編輯]