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

履歴 編集

function
<filesystem>

std::filesystem::path::native(C++17)

const string_type& native() const noexcept;

概要

システムの文字コードとしてパス文字列を取得する。

戻り値

*thisが保持するシステムのネイティブフォーマットを持つパスを返す。

POSIXベースシステムでの例

#include <iostream>
#include <filesystem>

namespace fs = std::filesystem;

int main()
{
  fs::path p = "/usr/bin/clang";

  // 代入されたパスがそのまま返る
  const std::string& s = p.native();
  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 std::wstring& s = p.native();
  std::wcout << s << std::endl;
}

出力

foo/bar

バージョン

言語

  • C++17

処理系