Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何使用迭代器删除两个连续的行?
我正在尝试使用 QT3.3 创建一个表单来保存用户和密码。但我也想修改和删除用户名和密码。我可以删除用户名,但我无法删除下一行。我一直使用的代码是:
QStringList::Iterator it; it = qFind(lines.begin(), lines.end(), str); if(it != lines.end()) { lines.erase(it); }
任何人都可以提出任何建议吗?
QStringList::erase返回一个迭代器,该迭代器引用您刚刚删除的元素后面的元素,因此:
QStringList::erase
it = lines.erase(it); // it now references the line after the erased one, so go again to delete that: if(it != lines.end()) { lines.erase(it); }
另外,必须:您使用 Qt 3.3 有什么原因吗?现在已经很古老了。