【发布时间】:2017-03-23 04:17:27
【问题描述】:
我无法从我拥有的向量类型字符串中删除某些索引。我的任务是用 html 标签(html、head 等)填充向量,但我需要去掉不匹配的标签(假设只有 p、br、img)。每次我在 for 循环之后打印向量时,我都会得到一个杂散的 br 和 p。非常感谢您的帮助!
for (int i = 0; i < tagStorage.size(); i++) {
if (tagStorage[i].find_first_of('/') == true) { //searches for closing tags
closingTags.push_back(tagStorage[i]);
}
else if (tagStorage[i].find("<p>") != string::npos) { //searches for <p> tag
noMatch.push_back(tagStorage[i]);
tagStorage.erase(tagStorage.begin() + i); //erase tag
}
else if (tagStorage[i].find("<br>") != string::npos) { //searches for <br> tag
noMatch.push_back(tagStorage[i]);
tagStorage.erase(tagStorage.begin() + i); //erase tag
}
else if (tagStorage[i].find("<img") != string::npos) { //searches for <img ..> tag
noMatch.push_back(tagStorage[i]);
tagStorage.erase(tagStorage.begin() + i); //erase tag
}
else {
openingTags.push_back(tagStorage[i]);
}
}
【问题讨论】: