std::filesystem::current_path
来自 cppreference.cn
< 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) 在底层 OS API 错误时抛出 std::filesystem::filesystem_error,并以 OS 错误代码作为错误代码实参构造。
[编辑] 注解
当前工作目录是与进程关联的目录,它被用作相对路径的路径名解析的起始位置。
许多操作系统返回的当前路径是一个危险的全局变量。它可能被第三方或系统库函数,或另一个线程意外更改。
[编辑] 示例
运行此代码
可能的输出
Current path is "D:/local/ConsoleApplication1" Current path is "E:/Temp"
[编辑] 参见
(C++17) |
返回适合临时文件的目录 (函数) |