void print(std :: vector&l ...

问题描述 投票:0回答:0
我正在尝试使用

GCC

版本
14.2.1

编译此代码。当我尝试编译此代码时,我会得到各种错误,例如:

... /usr/include/c++/14.2.1/format:4065:10: error: static assertion failed: std::formatter must be specialized for each type being formatted 4065 | (is_default_constructible_v<formatter<_Args, _CharT>> && ...), | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ... /usr/include/c++/14.2.1/format:4095:38: error: use of deleted function ‘std::formatter<_Tp, _CharT>::formatter() [with _Tp = std::vector<int>; _CharT = char]’ 4095 | formatter<_Tp, _CharT> __f; | ^~~ ... /usr/include/c++/14.2.1/format:4096:42: error: ‘struct std::formatter<std::vector<int>, char>’ has no member named ‘parse’ 4096 | this->_M_pc.advance_to(__f.parse(this->_M_pc)); | ~~~~^~~~~ test.cpp: In function ‘void print(std::vector<int>)’: test.cpp:6:21: error: call to consteval function ‘std::basic_format_string<char, std::vector<int, std::allocator<int> >&>("{}")’ is not a constant expression 6 | std::println("{}", v); | ~~~~~~~~~~~~^~~~~~~~~ ... /usr/include/c++/14.2.1/format:3730:25: error: static assertion failed: std::formatter must be specialized for the type of each format arg 3730 | static_assert(is_default_constructible_v<formatter<_Tq, _CharT>>, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14.2.1/format:3730:25: note: ‘std::is_default_constructible_v<std::formatter<std::vector<int>, char> >’ evaluates to false /usr/include/c++/14.2.1/format:3741:38: error: no matching function for call to ‘std::basic_format_arg<std::basic_format_context<std::__format::_Sink_iter<char>, char> >::basic_format_arg(std::vector<int>&)’ 3741 | basic_format_arg<_Context> __arg(__v); | ^~~~~ ...
thehere的link
与编译器资源管理器的链接。该代码也不适用于编译器资源管理器。我还尝试用

clang

汇编,但也失败了。我正在使用以下方式编译代码:
g++ -std=c++23 main.cpp

我做错了什么?我该如何解决?
    

这里的问题是basic_format_string

机制不知道如何格式化向量。  
Https://en.cppreference.com/w/cpp/io/println标识可以格式化的事物的集合,STL容器不属于该列表的一组。

c++ vector c++23 fmt
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.