gpt4 book ai didi

c++ - 格式化没有这样的文件或目录

转载 作者:行者123 更新时间:2023-12-04 11:58:57 28 4
gpt4 key购买 nike

我试图使用 C++ 格式实用程序 (std::format)。我试图编译这个简单的程序:

#include <format>

int main()
{
std::cout << std::format("{}, {}", "Hello world", 123) << std::endl;

return 0;
}
当我尝试使用 g++ -std=c++2a format_test.cpp 进行编译时,它给了我这个:
format_test.cpp:1:10: fatal error: format: No such file or directory
1 | #include <format>
|
我有 GCC 10.2.0

最佳答案

据此:https://en.cppreference.com/w/cpp/compiler_support当前没有支持“文本格式”( P0645R10std::format )的编译器。 (截至 2020 年 12 月)
那篇论文定义的功能测试宏是__cpp_lib_format (也列出 here ),因此您可以编写这样的代码来检查:

#if __has_include(<format>)
#include <format>
#endif

#ifdef __cpp_lib_format
// Code with std::format
#else
// Code without std::format, or just #error if you only
// want to support compilers and standard libraries with std::format
#endif

该提案还链接到 https://github.com/fmtlib/fmt作为一个完整的实现,使用 fmt::format而不是 std::format .尽管您必须跳过一些麻烦来链接依赖项或将其添加到您的构建系统,并在必要时处理许可/确认。
你的例子 {fmt} : https://godbolt.org/z/Ycd7K5

关于c++ - 格式化没有这样的文件或目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65083544/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com