C++ regex_replace返回错误字符串

C++ regex_replace返回错误字符串,c++,mustache,C++,Mustache,我试着做一个小胡子渲染器: std::string Mustache::render(const std::string& tmplt,const std::map<std::string,std::string>& context) { std::string result = tmplt; for(std::map<std::string,std::string>::const_iterator it=context.begin(); it

我试着做一个小胡子渲染器:

std::string Mustache::render(const std::string& tmplt,const std::map<std::string,std::string>& context)
{
   std::string result = tmplt;
   for(std::map<std::string,std::string>::const_iterator it=context.begin(); it!=context.end(); ++it)
   {
      std::regex reg("({{"+it->first+"}})");
      result = std::regex_replace(result,reg,std::string(it->second));
   }

    return result;
}
std::string Mustache::render(const std::string和tmplt,const std::map和context)
{
std::string result=tmplt;
对于(std::map::const_迭代器it=context.begin();it!=context.end();+it)
{
std::regex reg(“({{it->first+“}}”);
result=std::regex_replace(result,reg,std::string(it->second));
}
返回结果;
}
我用以下方法测试这段代码:

std::map<std::string, std::string> context;

context["test"] = "render-test";

std::cout <<  Mustache::render("It's a simple {{test}}");
std::映射上下文;
上下文[“测试”]=“渲染测试”;
std::cout试试看


std::您的正则表达式可能有
“(“
”)
括号,所以这可能是个问题谢谢!这只是一个大错误!
std::cout <<  Mustache::render("It's a simple {{test}}", context);
std::cout <<  Mustache::render("It's a simple {{test}}");