c++ - Access QVector element index by its content -
i have qvector
of qstrings
, want remove element content, don't know how find index of it. know how can remove it? don't want iterate on , compare content value.
my qvector
declared follows:
qvector <qstring> user_valid;
and want remove content, example element value "marigold":
user_valid.remove(user_valid.find("marigold");
thank in advance!
ok, following if you:
use
qstringlist
instead ofqvector<qstring>
has convenience methods can useful you; more common , hence comprehensive. spare 1 method call in case.just use removeone() and/or removeall() methods depending on exact scenario.
therefore, writing this:
qstringlist user_valid; user_valid << "marigold" << "cloud" << "sun" << "rain"; user_valid.removeone("marigold"); // user_valid: ["cloud", ,"sun", "rain"]
if insist on using qvector<qstring>
- bad idea in opinion -, need index first indexof() method, writing this:
user_valid.remove(user_valid.indexof("marigold"));
Comments
Post a Comment