std::filesystem:: temp_directory_path
|
定义于头文件
<filesystem>
|
||
|
path temp_directory_path
(
)
;
|
(1) | (C++17 起) |
|
path temp_directory_path
(
std::
error_code
&
ec
)
;
|
(2) | (C++17 起) |
返回适合存放临时文件的目录位置。
目录 |
参数
(无)
返回值
适用于存放临时文件的目录。该路径保证存在且为目录。接受 error_code & 参数的重载版本在出错时返回空路径。
异常
任何未标记为
noexcept
的重载在内存分配失败时可能抛出
std::bad_alloc
。
注释
在POSIX系统中,路径可能来自环境变量
TMPDIR
,
TMP
,
TEMP
,
TEMPDIR
的指定值,若这些变量均未设置,则返回路径
"/tmp"
。
在 Windows 系统上,路径通常是由
GetTempPath
返回的路径。
示例
#include <filesystem> #include <iostream> namespace fs = std::filesystem; int main() { std::cout << "Temp directory is " << fs::temp_directory_path() << '\n'; }
可能的输出:
Temp directory is "C:\Windows\TEMP\"
参阅
|
创建并打开一个临时自动删除文件
(函数) |
|
|
(C++17)
|
返回或设置当前工作目录
(函数) |