碰到这个问题时,我一开始时不以为然,但是仔细思考之后,发现其中大有玄机,玄机就在下面的代码里:
void mask(forward_list<string> &fl,const string &s1,const string &s2){
auto prev=fl.before_begin();
auto curr=fl.begin();
while(1){
if(*curr==s1){
fl.insert_after(curr,s2);
return;
}else{
prev=curr;
++curr;
if(curr==fl.end()) break;
}
}
fl.insert_after(prev,s2);
}
仔细研读以上代码,你就可以解决你的问题了