C++ C++;fmt库。部分变元替换
我有一个大模板(从文件加载),其中我应该用实际值替换命名参数。问题是,我需要在两个不同的函数中执行此操作,因此需要在C++ C++;fmt库。部分变元替换,c++,fmt,C++,Fmt,我有一个大模板(从文件加载),其中我应该用实际值替换命名参数。问题是,我需要在两个不同的函数中执行此操作,因此需要在func1()和func2()中替换部分命名参数 所需的行为是,下面返回myarg1 myarg2 #include <iostream> #include <string> #include <fmt/core.h> std::string func1(std::string& templ) { return fmt::fo
func1()
和func2()
中替换部分命名参数
所需的行为是,下面返回myarg1 myarg2
#include <iostream>
#include <string>
#include <fmt/core.h>
std::string func1(std::string& templ) {
return fmt::format(templ, fmt::arg("arg1", "myarg1"));
}
std::string func2(std::string& templ) {
return fmt::format(templ, fmt::arg("arg2", "myarg2"));
}
int main() {
std::string templ = "{arg1} {arg2}";
templ = func1(templ);
templ = func2(templ);
std::cout << templ << std::endl;
}
#包括
#包括
#包括
std::string func1(std::string和templ){
返回fmt::format(模板,fmt::arg(“arg1”,“myarg1”);
}
std::string func2(std::string和templ){
返回fmt::format(模板,fmt::arg(“arg2”,“myarg2”);
}
int main(){
std::string temp=“{arg1}{arg2}”;
templ=func1(templ);
temp=func2(temp);
std::cout否,{fmt}要求在一次调用中传递所有参数。fmt::format
不是搜索和替换函数。您使用了错误的库。谢谢!很棒的库。