Как перебрать вектор строки C++ и удалить элементы на основе сравнения строк?
В частности, если строка начинается с заданной подстроки.
Базовый поток кода аналогичен (некорректному) примеру программы C++ ниже.
#include
#include
#include
#include
using namespace std;
int main()
{
vector data={
"bracelet",
"brachen",
"busy",
"braces",
"brake",
"bread",
"biscuit"
};
for (vector::iterator t=data.begin(); t!=data.end(); ++t)
{
// if string starts with "br"
if (*t.find("br", 0) == 0)
// erase the element from the vector
data.erase(t);
}
return 0;
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... g-elements