7

如何从输出中删除 {}?

#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

4

1 回答 1

22

我引用fmt api

#include <fmt/ranges.h>

std::vector<int> v = {1, 2, 3};
fmt::print("{}", fmt::join(v, ", "));
// Output: "1, 2, 3"
于 2019-12-11T07:55:38.453 回答