问题
In a related question ("std::string formatting like sprintf") I learned about this awesome new C++20 header <format>.
However, there seems to be no supporting compiler. Is this correct or is there a way to use it anyway?
I'm using g++ 9.3 with the -std=c++2a
flag and the library <format>
is not recognised.
#include <format> // fatal error: format: No such file or directory
#include <iostream>
int main(){
std::cout << std::format("Hello {}!", "World");
}
g++-9 test.cpp -o test -std=c++2a
回答1:
Use libfmt. The <format>
header is essentially a standardized libfmt (with a few small features removed, if I remember correctly).
来源:https://stackoverflow.com/questions/61441494/how-to-use-the-format-header