- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经成功使用了 fmt
图书馆之前,所以我不完全确定为什么我有这个问题。首先,我将向您展示产生错误的代码:
void Logger::AttachSink(const std::string & id, LogSink sink) {
using namespace std::literals;
auto id_found = sinks.find(id) != std::endl(sinks);
if(!id_found) {
sinks.insert(std::make_pair(id, sink));
Info(
fmt::format(
"Sink \"{}\" Attached"s,
id
) // This is the line where the error is apparently happening, and I'm assuming the `id` is the culprit for some reason.
);
}
}
这是构建日志(注意:我使用 VSCode 作为编辑器,使用 CMake 使用 Visual Studio 2019 的编译器构建项目):
[main] Building folder: [WORKSPACE]
[build] Starting build
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.exe" --build [WORKSPACE]/build --config Debug --target ALL_BUILD -- /maxcpucount:6
[build] Microsoft (R) Build Engine version 16.7.0+b89cb5fde for .NET Framework
[build] Copyright (C) Microsoft Corporation. All rights reserved.
[build]
[build] logging.cpp
[build] [WORKSPACE]\build\vcpkg_installed\x64-windows\include\fmt\core.h(1073,9): error C2338: Cannot format argument. To make type T formattable provide a formatter<T> specialization: https://fmt.dev/latest/api.html#formatting-user-defined-types [[WORKSPACE]\build\drakeng\drakeng.vcxproj]
[build] [WORKSPACE]\build\vcpkg_installed\x64-windows\include\fmt\core.h(1070): message : while compiling class template member function 'int fmt::v7::detail::arg_mapper<Context>::map(...)' [[WORKSPACE]\build\drakeng\drakeng.vcxproj]
[build] with
[build] [
[build] Context=fmt::v7::basic_format_context<std::back_insert_iterator<fmt::v7::detail::buffer<char>>,char>
[build] ]
[build] [WORKSPACE]\build\vcpkg_installed\x64-windows\include\fmt\core.h(1259): message : see reference to function template instantiation 'int fmt::v7::detail::arg_mapper<Context>::map(...)' being compiled [[WORKSPACE]\build\drakeng\drakeng.vcxproj]
[build] with
[build] [
[build] Context=fmt::v7::basic_format_context<std::back_insert_iterator<fmt::v7::detail::buffer<char>>,char>
[build] ]
[build] [WORKSPACE]\build\vcpkg_installed\x64-windows\include\fmt\core.h(1084): message : see reference to class template instantiation 'fmt::v7::detail::arg_mapper<Context>' being compiled [[WORKSPACE]\build\drakeng\drakeng.vcxproj]
[build] with
[build] [
[build] Context=fmt::v7::basic_format_context<std::back_insert_iterator<fmt::v7::detail::buffer<char>>,char>
[build] ]
[build] [WORKSPACE]\build\vcpkg_installed\x64-windows\include\fmt\core.h(1241): message : see reference to alias template instantiation 'fmt::v7::detail::mapped_type_constant<const std::basic_string<char,std::char_traits<char>,std::allocator<char>>,Context>' being compiled [[WORKSPACE]\build\drakeng\drakeng.vcxproj]
[build] with
[build] [
[build] Context=fmt::v7::basic_format_context<std::back_insert_iterator<fmt::v7::detail::buffer<char>>,char>
[build] ]
[build] [WORKSPACE]\build\vcpkg_installed\x64-windows\include\fmt\core.h(1400): message : see reference to function template instantiation 'unsigned __int64 fmt::v7::detail::encode_types<Context,const std::basic_string<char,std::char_traits<char>,std::allocator<char>>,>(void)' being compiled [[WORKSPACE]\build\drakeng\drakeng.vcxproj]
[build] with
[build] [
[build] Context=fmt::v7::basic_format_context<std::back_insert_iterator<fmt::v7::detail::buffer<char>>,char>
[build] ]
[build] [WORKSPACE]\build\vcpkg_installed\x64-windows\include\fmt\core.h(1834): message : see reference to class template instantiation 'fmt::v7::format_arg_store<fmt::v7::basic_format_context<std::back_insert_iterator<fmt::v7::detail::buffer<char>>,char>,const std::basic_string<char,std::char_traits<char>,std::allocator<char>>>' being compiled [[WORKSPACE]\build\drakeng\drakeng.vcxproj]
[build] [WORKSPACE]\drakeng\logging.cpp(24): message : see reference to function template instantiation 'std::basic_string<char,std::char_traits<char>,std::allocator<char>> fmt::v7::format<std::string,const std::string&,char>(const S &,const std::string &)' being compiled [[WORKSPACE]\build\drakeng\drakeng.vcxproj]
[build] with
[build] [
[build] S=std::string
[build] ]
[build] Build finished with exit code 1
这些错误让它听起来像 fmt
没有 fmt::formatter<std::string>
特化对我来说听起来不对,所以我要么配置错误,要么不包含标题或其他内容。坦率地说,我很困惑。一旦我得到答案,知道我的运气可能会很愚蠢。无论如何,提前感谢您提供的任何帮助。
最佳答案
好吧,显然这个错误不是由我认为的原因引起的(谢谢,Visual C++ 编译器错误消息, super 有用!/s)。因此,要解释实际发生的事情:
Logger::Info
调用一个更通用的函数 Logger::Log(LoggingLevel level, const std::string & message)
.Logger::Log
也叫 fmt::format
在其中格式化一些附加信息以保存到日志中。fmt::format
的论点之一电话是level
然后需要将其转换为字符串(我选择创建一个 ToString
函数而不是为其创建一个 fmt::formatter
)。ToString
函数返回 std::optional<std::string>
“干净地”处理无效值。好吧,显然我忘了调用.value_or
在返回值上,THAT 是导致错误的原因。不幸的是,没有一条错误消息甚至提到与该行有关的任何内容,因此浪费了相当多的几分钟/几小时。
关于c++ - 为什么 fmt::format 不接受字符串作为参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64508627/
在我们的项目中,我们决定在我们的项目中使用最新的 fmt 版本 (6.2.0) 并主要使用 printf 功能,因为我们在广泛使用 printf 的地方进行日志记录。 我使用 fmt 包中包含的 CM
JSTL 标签用来绑定数据源(.properties)文件,JSTL 标签用来从指定的资源文件中调用信息。 语法 JSP 标签的语法如下: 代码块 其中: basename:指定要
我有以下 JSTL: enumValue.reputation 给出“非常好”、“完美”等字符串,对于这种情况,我需要将其小写“非常好”、“完美”。怎么把它变成小写?
为什么是这样fmt::format_to(OutputIt, ...)而不是 fmt::print(OutputIt, ...) ?? 我目前正在熟悉 {fmt} , 一个/现代 C++ 格式库。 在
所以我目前正在开始使用 Rust,并且正在阅读我的 Rust By Example。 做练习,边玩边玩代码。 但在 RBE Display函数描述它将 Fmt::Display 描述为比 Fmt::D
我不确定如何命名这个问题,因为我是 Rust 新手,所以请随意提出修改建议。 我有两个结构。一个是 Job 结构,其中包含一些数字,例如作业需要多长时间等。另一个是 JobSequence,其中包含
我不确定如何命名这个问题,因为我是 Rust 新手,所以请随意提出修改建议。 我有两个结构。一个是 Job 结构,其中包含一些数字,例如作业需要多长时间等。另一个是 JobSequence,其中包含
关于Golang中的标准I\O,网上所有的教程,无一异常(exception)地讨论和使用bufio,我测试过,效果很好。 但我的问题是关于使用 fmt 包读取标准输入,这要么给我错误,要么陷入循环。
正如标题,我很难描述这个问题。所以我在下面展示了示例代码、输入和输出。 package main import ( "fmt" ) func main() { for i := 1;
我正在尝试在我的 JSP Web 应用程序上本地化货币,问题是当我要求语言环境时,我只得到语言代码(“en”)而不是完整的语言和国家代码(“en_US”)。问题是,当 setLocale 的值不包含语
我使用的是 MACOS Mojave 版本 10.14.3,需要使用 GNU 编译器而不是 clang。 我使用 brew install gcc 安装了 gcc 编译器.然后我使用 brew ins
我正在尝试编译一些代码,但出现了一个非常奇怪的错误: the trait core::fmt::Show is not implemented for the type core::fmt::Show
我是 Go 语言和编程的新手。 谁能解释错误的含义以及我该如何解决? 最佳答案 使用 fmt.Println 而不是 fmt.PrintLn。将字母 L 小写。 关于go - undefined :
package main import ( "fmt" ) func main() { fmt.Printf("%c, %x, %x", 'ᚵ', 'ᚵ', "ᚵ") } 输出: ᚵ,
每当我在 Windows cmd 上的 Go 中运行 fmt.Print("\033c") 时,它不会清除屏幕,而是在我执行 console 时打印 c。 log("\033c") 在 javascr
我正在使用字典进行一些测试,为此,我以一种格式从数据库中打印出我想要的 Float64 值,以便将它们复制并粘贴到我的测试结构数组中,但是当我的测试失败时,我注意到这些值不同,但仅相差 0.00000
我目前有一个项目是这样组织的: ~/code/go /bin /pkg /src /proj/main.go
我目前正在做一个 spring 项目,我不得不在我的 JSP 中使用 fmt 标签。事实上 fmt 标签对我来说工作正常,它从 messages.properties 读取正确的值文件。 例如: 在
我想知道{fmt}库是否只允许修改包含多个位置参数的字符串中的一个位置参数? 这是我的测试不起作用,{fmt}文档未显示解决方案 std::string text = "{name} is {nb}
Closed. This question is not reproducible or was caused by typos。它当前不接受答案。 想改善这个问题吗?更新问题,以便将其作为on-to
我是一名优秀的程序员,十分优秀!