我想使用std::format
,但Visual Studio显示std
命名空间中没有成员format
。
这似乎是C++20的新功能。有没有办法使其可用?
我想使用std::format
,但Visual Studio显示std
命名空间中没有成员format
。
这似乎是C++20的新功能。有没有办法使其可用?
std::format
。fmt::
)和https://github.com/mknejp/std-format(将所有内容放在std::experimental::
中)。std
。如果我必须处理这样的事情,我会选择以下解决方案:
添加一个#define <some-unique-name>_format <wherever>::format
,然后使用<some-unique-name>_format
。
然后,一旦你获得了std::format
支持,请搜索并替换<some-unique-name>_format
为std::format
并丢弃#define
。
format
要好。std
,否则会产生未定义的行为。 - S.S. Annestd::format
! - J. Willus<format>
后将其替换掉。#include <string>
#include <version>
#ifndef __cpp_lib_format
#include <fmt/core.h>
using fmt::format;
#else
#include <format>
using std::format;
#endif
int main()
{
std::string a = format("test {}",43);
return 0;
}
std::format
。只需使用/std:c++latest
编译即可。
std::format
。 - Jonathan Wood<format>
头文件,所以我觉得你可能运气不好。 - Adrian Mole