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

履歴 編集

function
<filesystem>

std::filesystem::path::generic_display_string(C++26)

std::string generic_display_string() const;

概要

表示に適したリテラルエンコーディングで、環境非依存パスフォーマットのパス文字列を取得する。

std::format()std::print()で出力するのに適した文字列を返す。

戻り値

以下と等価である:

return std::format("{:g}", *this);

備考

  • 戻り値の文字列は、フォーマット (std::format()) や出力 (std::print()) で使用するのに適している
  • リテラルエンコーディングがUTF-8であり、パスが妥当なUnicodeであれば (Windowsのほとんどのパスがそうである)、文字コード変換は無損失となる

#include <print>
#include <filesystem>

namespace fs = std::filesystem;

int main()
{
  fs::path p = "foo\\bar"; // ネイティブフォーマットのパス (ディレクトリ区切り文字がバックスラッシュ)

  std::string s = p.generic_display_string();
  std::print("{}\n", s);
}

出力

foo/bar

バージョン

言語

  • C++26

処理系

関連項目

参照