![](/img/trans.png)
[英]Why does std::experimental::filesystem::path not accept wildcards like “*”?
[英]Path concat difference between std::filesystem and std::experimental::filesystem
我想從std::experimental::filesystem
遷移到std::filesystem
,但我的單元測試開始中斷。 我將 Windows、VS2019 和 MSVC 編譯器與/std:c++latest
。
我將問題縮小到標准和 實驗代碼庫中的 append 方法(和operator/=
)之間的差異。
#include <filesystem>
#include <experimental/filesystem>
int main() {
std::filesystem::path p1 = "C:\\temp";
p1 /= "\\test\\file.txt"; // Expected: C:\temp\test\file.txt, Actual C:\test\file.txt
std::experimental::filesystem::path p2 = "C:\\temp";
p2 /= "\\test\\file.txt"; // Expected: C:\temp\test\file.txt, Actual C:\temp\test\file.txt
}
問題:如何使用std::filesystem
在 Windows 上附加兩個路徑組件以獲取C:\\temp\\test\\file.txt
?
當您附加絕對路徑時,它會替換p1
所有組件,您需要從\\\\test\\\\file.txt
刪除前導斜杠以使其成為相對路徑,以便將其附加到p1
:
p1 /= "test\\file.txt";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.