- filesystem[meta header]
- std::filesystem[meta namespace]
- path[meta class]
- function[meta id-type]
- cpp17[meta cpp]
std::u16string generic_u16string() const;UTF-16エンコードで、環境非依存パスフォーマットのパス文字列を取得する。
*thisが保持するシステムの環境非依存パスフォーマットを持つパスを、UTF-16エンコードで返す。
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
fs::path p = "/usr/bin/clang";
const std::u16string s = p.generic_u16string();
}- p.generic_u16string()[color ff0000]
#include <cassert>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
fs::path p = "foo\\bar";
const std::u16string s = p.generic_u16string();
assert(s == u"foo/bar");
}- p.generic_u16string()[color ff0000]
Windowsでの例は、Visual C++が正式にファイルシステムライブラリをサポートしていないことから、未検証のサンプルコード・出力となっている。
- C++17
- Clang:
- GCC, C++17 mode: 8.1
- Visual C++: