Visual Studio中的C ++ 20支持
我想使用 std :: format
,但是Visual Studio说 std
命名空间没有成员 format 。
I'm wanting to use std::format
but Visual Studio says the std
namespace has no member format
.
看来这是C ++ 20的新功能。有没有办法使它可用?
It appears this is new for C++20. Is there a way to make it available?
截至撰写本文时,没有C ++标准库实现 std :: format
。
As of the time of writing, no C++ standard library implements std::format
.
网络上有多种实现方式,例如 https://github.com/fmtlib/fmt (可能是提案的原始来源,位于 fmt ::
)和 https://github.com/mknejp/std-format (这会将所有内容放入 std :: experimental :: $ c>)。
There are various implementations available on the web, like https://github.com/fmtlib/fmt (presumably the original source of the proposal, in fmt::
) and https://github.com/mknejp/std-format (which puts everything in std::experimental::
).
我不建议将它们放入 std
。如果我必须处理类似的事情,我将寻求的解决方案是:
I wouldn't recommend pulling these into std
. If I had to deal with something like this, the solution I would go for would be:
-
添加
#define<某些唯一名称> _format< whereevergt; :: format
,然后使用<某些唯一名称> _format
。
然后,一旦获得 std :: format
支持,就可以进行搜索和替换<某些唯一名称> _format
与 std :: format
并抛弃#定义
。
Then, once you get std::format
support, search-and-replace <some-unique-name>_format
with std::format
and toss the #define
.
它使用宏,但是从长远来看,这比不使用宏要好。 格式
到处都是
It uses macros, but in the long run it's better than having unqualified format
everywhere.