GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cpprefjp - C++日本語リファレンス
  • GitHub Project

This view

  • Original page
  • New address

GeezerVison is showing cpprefjp.github.io — std::filesystem::path::u8string - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. filesystem
  3. path
  4. u8string

最終更新日時: 2026年09月19日 21時31分51秒 (JST)
rotarymars が更新

履歴 編集

function
<filesystem>

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

std::string u8string() const;   // (1) C++17
std::u8string u8string() const; // (1) C++20

概要

UTF-8エンコードで、パス文字列を取得する。

戻り値

*thisが保持するシステムのネイティブフォーマットを持つパスを、UTF-8エンコードで返す。

備考

  • C++20から、破壊的変更として戻り値の型がstd::stringからstd::u8stringに変更となっている。これは、UTF-8エンコードされた文字型としてchar8_tが追加され、char型と型レベルで区別できるようにしたためである

例

POSIXベースシステムでの例

#include <cassert>
#include <filesystem>

namespace fs = std::filesystem;

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

  // システムのマルチバイト文字コードからUTF-8に変換されたパス文字列が返される
  assert(s == u8"/usr/bin/clang");
}

出力

Windowsでの例

#include <cassert>
#include <filesystem>

namespace fs = std::filesystem;

int main()
{
  fs::path p = "foo/bar";
  auto s = p.u8string();

  // システムのマルチバイト文字コードからUTF-8に変換されたパス文字列が返される
  assert(s == u8"foo/bar");
}

出力

バージョン

言語

  • C++17

処理系

  • Clang: 9.0.1 ✅
  • GCC: 8.1 ✅
  • Visual C++: 2017 Update 7 ✅

関連項目

  • C++20 char8_t
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.