ARTICLE AD BOX
How do I iterate through a C++ vector of string and delete elements based on a string comparison?
The basic code flow is like the (incorrect) example C++ program below.
#include <iostream> #include <string> #include <vector> #include <cstdio> using namespace std; int main() { vector<string> data={ "bracelet", "brachen", "busy", "braces", "brake", "bread", "biscuit" }; for (vector<string>::iterator t=data.begin(); t!=data.end(); ++t) { // if string starts with "br" if (*t.rfind("br", 0) == 0) // erase the element from the vector *t.erase(); } return 0; }