• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function
    <filesystem>

    std::filesystem::path::c_str

    const value_type* c_str() const noexcept;
    

    概要

    システムの文字コードとしてC言語の文字列表現を取得する。

    戻り値

    native().c_str()と等価

    POSIXベースシステムでの例

    #include <iostream>
    #include <filesystem>
    
    namespace fs = std::filesystem;
    
    int main()
    {
      fs::path p = "/usr/bin/clang";
    
      // 代入されたパスがそのまま返る
      const char* s = p.c_str();
      std::cout << s << std::endl;
    }
    

    出力

    /usr/bin/clang
    

    Windowsでの例

    #include <iostream>
    #include <filesystem>
    
    namespace fs = std::filesystem;
    
    int main()
    {
      fs::path p = "foo/bar";
    
      // UTF-16エンコーディングで返る
      const wchar_t* s = p.c_str();
      std::wcout << s << std::endl;
    }
    

    出力

    foo/bar
    

    バージョン

    言語

    • C++17

    処理系