Namespaces
Variants

std::experimental::filesystem:: temp_directory_path

From cppreference.net
定义于头文件 <experimental/filesystem>
path temp_directory_path ( ) ;
path temp_directory_path ( error_code & ec ) ;
(1) (文件系统 TS)

返回适合存放临时文件的目录位置。

目录

参数

(无)

返回值

适用于存放临时文件的目录。该路径保证存在且为目录类型。接受 error_code& 参数的重载版本在出错时将返回空路径。

异常

The overload that does not take an error_code & parameter throws filesystem_error on underlying OS API errors, constructed with 待返回路径 as the first argument and the OS error code as the error code argument. std:: bad_alloc may be thrown if memory allocation fails. The overload taking an error_code & parameter sets it to the OS API error code if an OS API call fails, and executes ec. clear ( ) if no errors occur. This overload has
noexcept 规范:
noexcept

备注

在POSIX系统中,路径可能来自环境变量 TMPDIR , TMP , TEMP , TEMPDIR 的指定值,若这些变量均未设置,则返回路径 "/tmp"

在 Windows 系统中,该路径通常是由 GetTempPath 返回的路径。

示例

#include <experimental/filesystem>
#include <iostream>
namespace fs = std::experimental::filesystem;
int main()
{
    std::cout << "Temp directory is " << fs::temp_directory_path() << '\n';
}

可能的输出:

Temp directory is "C:\Windows\TEMP\"

参见

创建并打开一个临时自动删除文件
(函数)