简体   繁体   English

如何使用 std::format 打印容器的内容

[英]How to print contents of a container using std::format

Using fmtlib , we can print a container as follows:使用fmtlib ,我们可以按如下方式打印容器:

#include <vector>
#include <fmt/ranges.h>

int main() {
  std::vector<int> v = {1, 2, 3};
  fmt::print("{}\n", v);
}

Can I do the same in the c++20 standard library version?我可以在 c++20 标准库版本中做同样的事情吗?

Formatting ranges is not a part of C++20 std::format but P2286 proposes it for C++23.格式化范围不是 C++20 std::format的一部分,但P2286为 C++23 提出了它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM