std::print 应该能够打印 std::vector 吗?

问题描述 投票:0回答:1

使用

fmt
库的 C++ 代码按预期运行:

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

int main() {
  std::vector<int> v{4, 2, 7};
  fmt::println("{}", v);
}

我尝试将标准

print
标头与 g++-14 一起使用:

#include <print>
#include <vector>

void test() {
  std::vector<int> v{4, 2, 7};
  std::println("{}", v);
}

无法使用巨大的模板进行编译。有办法解决吗?

c++ fmt
1个回答
0
投票

您的标准库必须支持 P2585 才能在

std::format
上使用
std::vector
,并且根据 libstdc++ 实现状态页,尚不支持 P2585,因此您必须等待未来的版本。

© www.soinside.com 2019 - 2024. All rights reserved.