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

std::filesystem::last_write_time

Defined in header <filesystem>

std::filesystem::file_time_type last_write_time(const std::filesystem::path& p); std::filesystem::file_time_type last_write_time(const std::filesystem::path& p, std::error_code& ec)

(1)

(since C++17)

void last_write_time(const std::filesystem::path& p, std::filesystem::file_time_type new_time); void last_write_time(const std::filesystem::path& p, std::filesystem::file_time_type new_time, std::error_code& ec);

(2)

(since C++17)

1%29返回上次修改p,确定为访问成员st_mtime第九届会议的报告统计%28符号链接后面跟着%29,不抛出重载返回。file_time_type::min()关于错误。

2%29更改最后一次修改的时间。p,好像是在POSIX福蒂蒙斯%28符号链接跟随%29

参数

p

-

path to examine or modify

new_time

-

new modification time

ec

-

out-parameter for error reporting in the non-throwing overload

返回值

1%29最后一次修改的时间p

2%29%280%29

例外

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

noexcept规格:

noexcept

注记

不能保证在设置写入时间后,%281%29返回的值与传递给%282%29的参数相同,因为文件系统%27 s的时间可能比file_time_type...

二次

代码语言:javascript
复制
#include <iostream>
#include <chrono>
#include <iomanip>
#include <fstream>
#include <filesystem>
namespace fs = std::filesystem;
using namespace std::chrono_literals;
int main()
{
    fs::path p = fs::current_path() / "example.bin";
    std::ofstream(p.c_str()).put('a'); // create file
    auto ftime = fs::last_write_time(p);
 
    std::time_t cftime = decltype(ftime)::clock::to_time_t(ftime); // assuming system_clock
    std::cout << "File write time is " << std::asctime(std::localtime(&cftime)) << '\n';
 
    fs::last_write_time(p, ftime + 1h); // move file write time 1 hour to the future
    ftime = fs::last_write_time(p); // read back from the filesystem
 
    cftime = decltype(ftime)::clock::to_time_t(ftime);
    std::cout << "File write time is " << std::asctime(std::localtime(&cftime)) << '\n';
    fs::remove(p);
}

二次

可能的产出:

二次

代码语言:javascript
复制
File write time is Tue Mar 31 19:47:04 2015
 
File write time is Tue Mar 31 20:47:04 2015

二次

另见

file_time_type (C++17)

represents file time values (typedef)

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

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

扫码关注腾讯云开发者

领取腾讯云代金券