可以在C++ 20中使用std ::格式
我一直在尝试使用C ++ 20中包含的std ::格式
功能。据我所知,Clang 14应该支持此功能,但是由于某些原因,我会收到以下错误:在命名空间'std'
中没有名为“格式”的成员。根据 cppreference的编译器支持图表,文本格式应由Clang支持,但我是我仍会收到此错误。我对问题的含义不知所措。
I've been trying to use the std::format
function included in C++20. As far as I can tell, clang 14 is supposed to support this feature, but for some reason I am receiving the following error: no member named 'format' in namespace 'std'
. According to cppreference's compiler support chart, text formatting should be supported by clang, but I'm still receiving this error. I'm at a loss for what the issue is.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
std::format
在 libc++ 14 中不完整,因此默认禁用 。 您需要传递LIBCXX_ENABLE_INCOMPLETE_FEATURES
构建 llvm 时的参数 以启用该功能。std::format
现已在 libc++17 中完全可用。如果您无法使用最新版本的 libc++ 可以使用 https://github.com/fmtlib/fmt。
std::format
is not complete in libc++ 14 so is disabled by default. You need to pass theLIBCXX_ENABLE_INCOMPLETE_FEATURES
parameter when building llvm to enable the feature.std::format
is now fully available in libc++17.If you can't use the latest verson of libc++ can use https://github.com/fmtlib/fmt.
如果你仔细观察,该单元格中有一个星号:
下面,它说:
,当您将鼠标悬停在版本号上时,它会显示:
未提及的是,默认情况下不启用不完整的功能。但这是有道理的,因为他们不希望用户依赖会破坏的 API/ABI。在我看来,正如这个问题所证明的那样,使用绿色表示该单元格是具有误导性的。
总之,最好使用第三方格式化库,直到文本格式化的标准实现在主要语言实现中完整、稳定且非实验性为止。
其他注意事项:
std::format
的标头。If you look closely, there is an asterisk in that cell:
Below, it says:
And when you hover, it says:
What's unsaid is that incomplete features are not enabled by default. But that makes sense since they wouldn't want users to depend on an API/ABI that will break. In my opinion, as also evidenced by this question, using green for this cell is misleading.
In conclusion, it's best to use the third party formatting library until the standard implementation of text formatting is complete, stable and non-experimental in major language implementations.
Other caveats:
std::format
.