c++20--std::format

作用

链接

编译器版本支持

g++版本至少是13。

g++ --version

升级g++编译器

案例

时间格式化

复制代码
#include <iostream>
#include <chrono>
#include <format> // C++20 <format> 库

int main() {
    // 获取当前时间(UTC)
    auto now = std::chrono::system_clock::now();
    
    // 格式化为 ISO 8601 字符串(如 "2025-08-07T12:34:56.789Z")
    std::string time_str = std::format("{:%Y-%m-%dT%H:%M:%S.%Z}", now);
    
    std::cout << time_str << std::endl;
    return 0;
}
相关推荐
Codeking__17 小时前
C++20的consteval和constinit(接C++11的constexpr)
算法·c++20
六bring个六3 天前
C++20协程
c++20·协程
C++实习生3 天前
Visual C++ 2005 Express 中文版
express·c++20
Ethan Wilson5 天前
VS2019 C++20 模块相关 C1001: 内部编译器错误
开发语言·c++·c++20
DYS_房东的猫6 天前
《 C++ 零基础入门教程》第10章:C++20 核心特性 —— 编写更现代、更优雅的 C++
java·c++·c++20
ice_junjun16 天前
C++20 线程返回值处理指南
c++20·c++ 多线程返回值
凌乱风雨121119 天前
从源码角度解析C++20新特性如何简化线程超时取消
前端·算法·c++20
shuai132_1 个月前
【无标题】
c++20
ULTRA??1 个月前
基于range的函数式编程C++,python比较
c++·python·kotlin·c++20
apocelipes1 个月前
从源码角度解析C++20新特性如何简化线程超时取消
c++·性能优化·golang·并发·c++20·linux编程