std::filesystem::current_path
來自 cppreference.com
< cpp | filesystem
定義於標頭檔案 <filesystem> |
||
path current_path(); |
(1) | (C++17 起) |
path current_path( std::error_code& ec ); |
(2) | (C++17 起) |
void current_path( const std::filesystem::path& p ); |
(3) | (C++17 起) |
void current_path( const std::filesystem::path& p, std::error_code& ec ) noexcept; |
(4) | (C++17 起) |
返回或改變當前路徑。
目錄 |
[編輯] 引數
p | - | 要更改為的當前工作目錄路徑 |
ec | - | 用於在非丟擲過載中報告錯誤的輸出引數 |
[編輯] 返回值
1,2) 返回當前工作目錄。
3,4) (無)
[編輯] 異常
任何未標記為 noexcept
的過載都可能在記憶體分配失敗時丟擲 std::bad_alloc。
1) 在底層作業系統 API 錯誤時丟擲 std::filesystem::filesystem_error,構造時以 OS 錯誤碼作為錯誤碼引數。
[編輯] 注意
當前工作目錄是與程序關聯的目錄,用作相對路徑路徑名解析的起始位置。
許多作業系統返回的當前路徑是一個危險的全域性變數。它可能被第三方或系統庫函式,或另一個執行緒意外更改。
[編輯] 示例
執行此程式碼
可能的輸出
Current path is "D:/local/ConsoleApplication1" Current path is "E:/Temp"
[編輯] 參閱
(C++17) |
返回適合臨時檔案的目錄 (function) |