名前空間
変種
操作

std::filesystem::path::generic_string、std::filesystem::path::generic_wstring、std::filesystem::path::generic_u8string、std::filesystem::path::generic_u16string、std::filesystem::path::generic_u32string

From cppreference.com
< cpp‎ | filesystem‎ | path
 
 
 
 
template< class CharT, class Traits = std::char_traits<CharT>,

          class Alloc = std::allocator<CharT> >
std::basic_string<CharT,Traits,Alloc>

    generic_string( const Alloc& a = Alloc() ) const;
(1) (C++17以降)
(2) (C++17以降)
std::string generic_string() const;
std::wstring generic_wstring() const;
std::u16string generic_u16string() const;
std::u32string generic_u32string() const;
(3)
std::string generic_u8string() const;
(C++17以降)
(C++20まで)
std::u8string generic_u8string() const;
(C++20以降)

内部パス名を、指定された文字列型に変換して返します。変換(ある場合)は次のように指定されます。

  • path::value_typechar の場合、変換(ある場合)はシステム依存です。これは、ネイティブエンコーディングがUTF-8であり、string() が変換を行わない典型的なPOSIXシステム(Linuxなど)の場合です。
  • それ以外の場合、path::value_typewchar_t の場合、変換(ある場合)は未指定です。これは、Windowsの場合で、wchar_t が16ビットであり、ネイティブエンコーディングがUTF-16である場合です。
  • それ以外の場合、path::value_typechar16_t の場合、ネイティブエンコーディングはUTF-16であり、変換方法は未指定です。
  • それ以外の場合、path::value_typechar32_t の場合、ネイティブエンコーディングはUTF-32であり、変換方法は未指定です。
  • それ以外の場合、path::value_typechar8_t の場合、ネイティブエンコーディングはUTF-8であり、変換方法は未指定です。

ディレクトリセパレーターとして '/' 文字が使用されます。

1) すべてのメモリ割り当ては a によって行われます。
3) u8string() の場合、結果のエンコーディングは常にUTF-8です。

目次

[編集] Parameters

a - 文字列の構築に使用するアロケータ
型要件
-
CharT は、エンコードされた文字型(charwchar_tchar8_t(C++20以降)char16_t、および char32_t)のいずれかである必要があります。

[編集] Return value

汎用パス名形式の内部パス名。指定された文字列型に変換されます。

[編集] 例外

実装定義の例外をスローする場合があります。

[編集] Example

#include <cstddef>
#include <filesystem>
#include <iomanip>
#include <iostream>
#include <span>
#include <string_view>
 
void print(std::string_view rem, auto const& str)
{
    std::cout << rem << std::hex << std::uppercase << std::setfill('0');
    for (const auto b : std::as_bytes(std::span{str}))
        std::cout << std::setw(2) << std::to_integer<unsigned>(b) << ' ';
    std::cout << '\n';
}
 
int main()
{
    std::filesystem::path p{"/家/屋"};
    std::cout << p << '\n';
 
    print("string    : ", p.generic_string());
    print("u8string  : ", p.generic_u8string());
    print("u16string : ", p.generic_u16string());
    print("u32string : ", p.generic_u32string());
    print("wstring   : ", p.generic_wstring());
}

実行結果の例

"/家/屋"
string    : 2F E5 AE B6 2F E5 B1 8B
u8string  : 2F E5 AE B6 2F E5 B1 8B
u16string : 2F 00 B6 5B 2F 00 4B 5C
u32string : 2F 00 00 00 B6 5B 00 00 2F 00 00 00 4B 5C 00 00
wstring   : 2F 00 00 00 B6 5B 00 00 2F 00 00 00 4B 5C 00 00

[編集] See also

パスをネイティブパス名形式から文字列に変換して返します。
(public member function) [編集]
English 日本語 中文(简体) 中文(繁體)