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(conststd::filesystem::path& p ); | (3) | (C++17 起) |
void current_path(conststd::filesystem::path& p, std::error_code& ec )noexcept; | (4) | (C++17 起) |
返回或更改当前路径。
目录 |
[编辑]参数
p | - | 更改当前工作目录所到的路径 |
ec | - | 不抛出重载中报告错误的输出形参 |
[编辑]返回值
1,2) 返回当前工作目录。
3,4) (无)
[编辑]异常
若内存分配失败,则任何不标记为 noexcept
的重载可能抛出 std::bad_alloc 。
1) 抛出 std::filesystem::filesystem_error,构造时以 OS 错误码为错误码实参。
[编辑]注解
当前工作目录是与进程关联的目录,它被用作相对路径的路径名解析中的起始位置。
许多操作系统返回的当前路径是危险的全局变量。第三方或系统库函数,或另一线程可能未经期待地更改它。
[编辑]示例
运行此代码
可能的输出:
当前路径为 "D:/local/ConsoleApplication1" 当前路径为 "E:/Temp"
[编辑]参阅
(C++17) | 返回一个适用于临时文件的目录 (函数) |