• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function
    <string>

    std::basic_string::operator basic_string_view

    operator basic_string_view<charT, traits>() const noexcept;           // (1) C++17
    constexpr operator basic_string_view<charT, traits>() const noexcept; // (1) C++20
    

    概要

    std::basic_string_view型に変換する。

    戻り値

    以下と等価:

    return std::basic_string_view<charT, traits>(data(), size());
    

    例外

    投げない

    #include <iostream>
    #include <string>
    
    int main()
    {
      std::string s = "Hello World";
      std::string_view sv = s;
    
      std::cout << sv.substr(0, 5) << std::endl;
      std::cout << s << std::endl;
    }
    

    出力

    Hello
    Hello World
    

    参照