std::experimental::filesystem:: file_time_type
From cppreference.net
<
cpp
|
experimental
|
fs
C++
Experimental
| Technical Specification | ||||
| Filesystem library (filesystem TS) | ||||
| Library fundamentals (library fundamentals TS) | ||||
| Library fundamentals 2 (library fundamentals TS v2) | ||||
| Library fundamentals 3 (library fundamentals TS v3) | ||||
| Extensions for parallelism (parallelism TS) | ||||
| Extensions for parallelism 2 (parallelism TS v2) | ||||
| Extensions for concurrency (concurrency TS) | ||||
| Extensions for concurrency 2 (concurrency TS v2) | ||||
| Concepts (concepts TS) | ||||
| Ranges (ranges TS) | ||||
| Reflection (reflection TS) | ||||
| Mathematical special functions (special functions TR) | ||||
| Experimental Non-TS | ||||
| Pattern Matching | ||||
| Linear Algebra | ||||
| std::execution | ||||
| Contracts | ||||
| 2D Graphics |
Filesystem library
| Classes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| File types | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
定义于头文件
<experimental/filesystem>
|
||
|
using
file_time_type
=
chrono
::
time_point
<
/*trivial-clock*/
>
;
|
(文件系统 TS) | |
表示文件时间。
trivial-clock
是一个实现定义的类型,满足
TrivialClock
要求,且足以表示文件系统所提供的文件时间值的精度和范围。
示例
运行此代码
#include <chrono> #include <experimental/filesystem> #include <fstream> #include <iomanip> #include <iostream> namespace fs = std::experimental::filesystem; using namespace std::chrono_literals; int main() { fs::path p = fs::current_path() / "example.bin"; std::ofstream(p.c_str()).put('a'); // 创建文件 auto ftime = fs::last_write_time(p); std::time_t cftime = decltype(ftime)::clock::to_time_t(ftime); // 假设为系统时钟 std::cout << "文件写入时间为 " << std::asctime(std::localtime(&cftime)) << '\n'; fs::last_write_time(p, ftime + 1h); // 将文件写入时间向后移动1小时 ftime = fs::last_write_time(p); // 从文件系统重新读取 cftime = decltype(ftime)::clock::to_time_t(ftime); std::cout << "文件写入时间为 " << std::asctime(std::localtime(&cftime)) << '\n'; fs::remove(p); }
可能的输出:
文件写入时间为 Tue Mar 31 19:47:04 2015 文件写入时间为 Tue Mar 31 20:47:04 2015
参见
|
获取或设置最后数据修改时间
(函数) |