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;
}
相关推荐
Max_uuc22 天前
【架构心法】逃离回调地狱:从 Protothreads 到 C++20 协程 (Coroutines) 的嵌入式进化
c++20
阿猿收手吧!1 个月前
【C++】C++20协程的await_transform和coroutine_handle
开发语言·c++·c++20
阿猿收手吧!1 个月前
【C++】 co_yield如何成为语法糖?解析其背后的Awaitable展开与协程状态跃迁
c++·c++20
吐泡泡_1 个月前
C++20(三路比较运算符)
c++20
啟明起鸣1 个月前
【C++20新特性】概念约束特性与 “模板线程池”,概念约束是为了 “把握未知对象”
开发语言·c++·c++20·模板线程池
linweidong1 个月前
虎牙C++面试题及参考答案(上)
stl·vector·线程·内存管理·c++20·c++面试·c++调用
吐泡泡_1 个月前
C++20(概念和约束)
c++20
訫悦1 个月前
体验在Qt中简单使用C++20的协程
qt·c++20·协程
fpcc2 个月前
C++20中的预处理器宏——__VA_OPT__
c++20
Codeking__2 个月前
C++20的consteval和constinit(接C++11的constexpr)
算法·c++20