首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::filesystem::temp_directory_path

Defined in header <filesystem>

?

?

path temp_directory_path(); path temp_directory_path( std::error_code& ec );

(1)

(since C++17)

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

参数

%280%29

返回值

适合临时文件的目录。该路径保证存在并成为一个目录。过载error_code&参数返回错误时的空路径。

例外

不占用std::error_code&参数抛文件系统[医]误差关于基础OS API错误,使用path to be returned作为第一个参数和操作系统错误代码作为错误代码参数。std::bad_alloc如果内存分配失败,则可能引发。过载std::error_code&参数,如果OSAPI调用失败,则将其设置为OSAPI错误代码,并执行ec.clear()如果没有错误发生。这个过载

noexcept规格:

noexcept

注记

在POSIX系统上,路径可能是环境变量中指定的路径。TMPDIR,,,TMP,,,TEMP,,,TEMPDIR,如果没有指定它们,则路径"/tmp"会被归还。

在Windows系统中,路径通常是由GetTempPath...

二次

代码语言:javascript
复制
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
    std::cout << "Temp directory is " << fs::temp_directory_path() << '\n';
}

二次

可能的产出:

二次

代码语言:javascript
复制
Temp directory is "C:\Windows\TEMP\"

二次

另见

tmpfile

creates and opens a temporary, auto-removing file (function)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com