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>
|
GCC10.2.0を持っています
これによると:https://en.cppreference.com/w/cpp/compiler_support現在、「テキストフォーマット」(P0645R10、std::format
)をサポートするコンパイラはありません。(2020年12月現在)
その論文で定義されている機能テストマクロは__cpp_lib_format
(ここにもリストされています)なので、次のようにコードを記述して次のことを確認できます。
#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
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加