Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/129.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;fmt库。部分变元替换_C++_Fmt - Fatal编程技术网

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
不是搜索和替换函数。您使用了错误的库。谢谢!很棒的库。