• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

    最終更新日時(UTC):
    が更新

    履歴 編集

    function
    <string_view>

    std::basic_string_view::starts_with

    constexpr bool starts_with(basic_string_view x) const noexcept; // (1)
    constexpr bool starts_with(CharT x) const noexcept;             // (2)
    constexpr bool starts_with(const CharT* x) const;               // (3)
    

    概要

    指定の文字列で始まるかを判定する。

    • (1) : *thisが参照する文字列範囲の先頭が、xが参照する文字列範囲と一致するかを判定する
    • (2) : *thisが参照する文字列範囲の先頭が、文字xと一致するかを判定する
    • (3) : *thisが参照する文字列範囲の先頭が、文字列xと一致するかを判定する

    戻り値

    例外

    • (1), (2) : 投げない

    #include <cassert>
    #include <string_view>
    
    int main()
    {
      const std::string_view sv = "aaabbbcccdddeee";
    
      // (1)
      {
        std::string_view svx = "aaa"; 
        assert(sv.starts_with(svx));
      }
    
      // (2)
      {
        assert(sv.starts_with('a'));
      }
    
      // (3)
      {
        assert(sv.starts_with("aaa"));
      }
    }
    

    出力

    バージョン

    言語

    • C++20

    処理系

    参照