std::filesystem::path::operator=
來自 cppreference.com
< cpp | filesystem | path
| path& operator=( const path& p ); |
(1) | (C++17 起) |
| path& operator=( path&& p ) noexcept; |
(2) | (C++17 起) |
| path& operator=( string_type&& source ); |
(3) | (C++17 起) |
| template< class Source > path& operator=( const Source& source ); |
(4) | (C++17 起) |
1) 將 *this 的內容替換為路徑名,使其原生與通用格式表示都等於 p 的。
2) 將 *this 的內容替換為路徑名,使其原生與通用格式表示都等於 p 的,可能使用移動語義: p 會處於某個有效但未指定的狀態。
3) 將 *this 的內容替換為一個新的路徑值,該值從自動檢測格式的 source 構造, source 會處於某個有效但未指定的狀態。等價於 assign(std::move(source)) 。
(4) 僅若 Source 與 path 不是同一型別,且滿足下列任一條件,才參與過載決議:
-
Source是 std::basic_string 或 std::basic_string_view 的特化,或 - std::iterator_traits<std::decay_t<Source>>::value_type 有效並指代一個可能是 const 限定的編碼字元型別( char, char8_t, (C++20 起)char16_t, char32_t, 或 wchar_t )。
目錄 |
[編輯] 引數
| p | - | - 要賦值的路徑 |
| source | - | - std::basic_string、std::basic_string_view、指向空終止字元/寬字元字串的指標,或指向空終止字元/寬字元序列的輸入迭代器。字元型別必須是 char、char8_t、(C++20 起)char16_t、char32_t、wchar_t 之一 |
[編輯] 返回值
*this
[編輯] 示例
執行此程式碼
#include <filesystem> namespace fs = std::filesystem; int main() { fs::path p = "C:/users/abcdef/AppData/Local"; p = p / "Temp"; // move assignment const wchar_t* wstr = L"D:/貓.txt"; p = wstr; // assignment from a source }
[編輯] 缺陷報告
下列更改行為的缺陷報告追溯地應用於以前出版的 C++ 標準。
| 缺陷報告 | 應用於 | 釋出時的行為 | 正確的行為 |
|---|---|---|---|
| LWG 3244 | C++17 | 缺少 Source 不能是 path 的約束 |
已新增 |
[編輯] 參閱
| 賦值內容 (公開成員函式) | |
構造一個 path(公開成員函式) |