<int> 使用 fmt 库将向量转换为字符串

Convert a vector<int> to string with fmt library

本文关键字:向量 转换 字符串 fmt lt int gt 使用      更新时间:2023-10-16

如何从输出中删除{}?

#include <iostream>
#include <vector>
#include <fmt/format.h>
#include <fmt/ranges.h>
int main () {
std::vector<int> v = {1,2,3};
std::string s = fmt::format("{}", v);
std::cout << s << 'n'; // output : {1, 2, 3}
return 0;
}

如何在上述代码的输出中删除"{"和"}"并仅打印:1、2、3

我引用fmt api:

#include <fmt/ranges.h>
std::vector<int> v = {1, 2, 3};
fmt::print("{}", fmt::join(v, ", "));
// Output: "1, 2, 3"