【问题标题】:Convert a vector<int> to string with fmt library使用 fmt 库将 vector<int> 转换为字符串
【发布时间】:2019-12-11 07:10:08
【问题描述】:

如何从输出中移除 {}?

#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

【问题讨论】:

标签: c++ fmt


【解决方案1】:

我引用fmt api

#include <fmt/ranges.h>

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-04
    • 1970-01-01
    • 2016-11-11
    相关资源
    最近更新 更多