希望这是一个愚蠢的问题。我有以下代码:
#include <iostream>
#include <fmt/format.h>
#include <string>
int main(){
double f = 1.23456789;
std::cout << fmt::format( "Hello {:f} how are you?\n", f ) << "\n";
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这按预期工作 -你好 1.234568 你好吗?
但是,如果我想将传递到 fmt::format 的字符串封装为变量,则会遇到编译器错误:
#include <iostream>
#include <fmt/format.h>
#include <string>
int main() {
double f = 1.23456789;
const char* m = "Hello {:f} how are you?\n"; //can't be constexpr, generated at run time
std::cout << fmt::format( m, f ) << "\n";
return 0;
}
Run Code Online (Sandbox Code Playgroud)
然而,在 MSVC 2022 上使用 …