How to use the <format> header

家住魔仙堡 提交于 2020-11-29 05:09:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!