我试图在一行中用'$'对分隔的一些字符串之间循环,用一个特定的值替换每个匹配,以便获得所有标记替换的输出行,但是我停留在第二场比赛,因为我不知道如何连接新的替换值:regex_search and regex_replace with Boost
const boost::regex expression("\\$[\\w]+\\$");
string fileLine("Mr $SURNAME$ from $LOCATION$");
string outLine;
string::const_iterator begin = fileLine.begin();
string::const_iterator end = fileLine.end();
boost::match_results<string::const_iterator> what;
boost::match_flag_type flags = boost::match_default;
while (regex_search(begin, end, what, expression, flags)) {
actualValue = valuesMap[what[0]];
ostringstream t(ios::out | ios::binary);
ostream_iterator<char, char> oi(t);
boost::regex_replace(oi, begin, end, expression, actualValue,
boost::match_default | boost::format_first_only);
outLine.append(t.str());
begin = what[0].second;
}
的问题是在outLine.append(t.str())作为连接不正确,因为后第一场比赛,outline拿着下一场比赛之前的一些角色。