std::experimental::filesystem::path::string,wstring,u8string,...
來自 cppreference.com
< cpp | experimental | fs | path
template< class CharT, class Traits = std::char_traits<CharT>, class Alloc = std::allocator<CharT> > |
(1) | (檔案系統 TS) |
(2) | (檔案系統 TS) | |
std::string string() const; |
||
std::wstring wstring() const; |
||
std::string u8string() const; |
||
std::u16string u16string() const; |
||
std::u32string u32string() const; |
||
返回本地路徑名格式的內部路徑名,轉換為特定的字串型別。如果進行轉換,則在待辦中指定。
1) 所有記憶體分配都由 a 執行。
2) 在 `u8string()` 的情況下,編碼始終為 UTF-8。
目錄 |
[編輯] 引數
(無)
[編輯] 返回值
本地路徑名格式的內部路徑名,轉換為指定的字串型別。
[編輯] 異常
可能丟擲實現定義的異常。
[編輯] 示例
執行此程式碼
#include <clocale> #include <cstdio> #include <experimental/filesystem> #include <fstream> #include <iostream> namespace fs = std::experimental::filesystem; int main() { std::setlocale(LC_ALL, "en_US.utf8"); std::locale::global(std::locale("en_US.utf8")); fs::path p = fs::u8path(u8"要らない.txt"); // native string representation can be used with OS APIs std::ofstream(p) << "File contents"; // this uses operator string() if (std::FILE* f = std::fopen(p.c_str(), "r")) { int ch; while ((ch=fgetc(f))!= EOF) putchar(ch); std::fclose(f); } // multibyte and wide representation can be used for output std::cout.imbue(std::locale()); std::cout << "\nFile name in narrow multibyte encoding: " << p.string() << '\n'; std::wcerr.imbue(std::locale()); std::wcerr << "File name in wide encoding: " << p.wstring() << '\n'; fs::remove(p); }
可能的輸出
File contents File name in narrow multibyte encoding: 要らない.txt File name in wide encoding: 要らない.txt
[編輯] 參閱
返回轉換為字串的通用路徑名格式的路徑 (公共成員函式) |