- filesystem[meta header]
- std::filesystem[meta namespace]
- path[meta class]
- function[meta id-type]
- cpp26[meta cpp]
std::string display_string() const;表示に適したリテラルエンコーディングで、パス文字列を取得する。
std::format()やstd::print()で出力するのに適した文字列を返す。
以下と等価である:
return std::format("{}", *this);- std::format[link /reference/format/format.md]
- 戻り値の文字列は、フォーマット (
std::format()) や出力 (std::print()) で使用するのに適している - リテラルエンコーディングがUTF-8であり、パスが妥当なUnicodeであれば (Windowsのほとんどのパスがそうである)、文字コード変換は無損失となる
#include <print>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
fs::path p = "/usr/bin/clang";
std::string s = p.display_string();
std::print("{}\n", s);
}- p.display_string()[color ff0000]
/usr/bin/clang
- C++26
- Clang: 22 [mark noimpl]
- GCC: 16.1 [mark noimpl]
- Visual C++: 2026 Update 2 [mark noimpl]
string()(システムのマルチバイト文字コードで取得する。C++26で非推奨)system_encoded_string()(システム依存エンコーディングで取得する)generic_display_string()(環境非依存フォーマットで取得する)formatter(std::format()での書式)
- P2319R5 Prevent path presentation problems
- 表示用のリテラルエンコーディングで文字列を取得するこの関数がC++26で追加された