名稱空間
變體
操作

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)*this 的內容替換為一個新的路徑值,該值從自動檢測格式的 source 構造,如同透過 path 建構函式 的過載 (4) 。等價於 assign(source)

(4) 僅若 Sourcepath 不是同一型別,且滿足下列任一條件,才參與過載決議:

目錄

[編輯] 引數

p - - 要賦值的路徑
source - - std::basic_stringstd::basic_string_view、指向空終止字元/寬字元字串的指標,或指向空終止字元/寬字元序列的輸入迭代器。字元型別必須是 charchar8_t(C++20 起)char16_tchar32_twchar_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
(公開成員函式) [編輯]