如何使用 std::format 打印容器的内容
How to print contents of a container using std::format
<format>
的文档在 cppreference is a bit lacking, with examples missing, so I checked fmtlib 上,以了解其潜力。
那里包含一个 example,显示如何打印 std::vector
的内容:
#include <vector>
#include <fmt/ranges.h>
int main() {
std::vector<int> v = {1, 2, 3};
fmt::print("{}\n", v);
}
如何在 c++20 标准库版本中做同样的事情?
格式化范围不是 C++20 的一部分 std::format
但 P2286 建议将其用于 C++23。
<format>
的文档在 cppreference is a bit lacking, with examples missing, so I checked fmtlib 上,以了解其潜力。
那里包含一个 example,显示如何打印 std::vector
的内容:
#include <vector>
#include <fmt/ranges.h>
int main() {
std::vector<int> v = {1, 2, 3};
fmt::print("{}\n", v);
}
如何在 c++20 标准库版本中做同样的事情?
格式化范围不是 C++20 的一部分 std::format
但 P2286 建议将其用于 C++23。