zoukankan      html  css  js  c++  java
  • qt 容器

     QList<QString> list;
     list << "A" << "B" << "C" << "D";
    
     QListIterator<QString> i(list);
     while (i.hasNext())
         qDebug() << i.next();

    Unlike STL-style iterators (covered below), Java-style iterators point between items rather than directly at items

    Then we call hasNext() to check whether there is an item after the iterator. If there is, we callnext() to jump over that item. The next() function returns the item that it jumps over。

    java迭代器指向item中间位置,next跳过item,并返回跳过的item。

    The remove() function removes the last item that we jumped over from the list. The call to remove() does not invalidate the iterator, so it is safe to continue using it.

    remove移除跳过的元素。迭代器不会失效。

    c++这边:

    在循环遍历一个容器时,需要根据条件删除其中的某个元素,如何处理iterator?答案是:对于序列式容器标准写法是这样:
    //vector<int> con;
    for(vector<int>::iterator iter=con.begin();
      iter!=con.end();)
    {
      if((*iter) == 99)
       iter=con.erase(iter);
      else
       ++iter;
    }
    对于关联容器是这样:
    //map<int,int> con;
    for(map<int,int>::iterator iter=con.begin();
      iter!=con.end();)
    {
      if(iter->second == 99)
       con.erase(iter++);
      else
       ++iter;
    }

  • 相关阅读:
    什么是透视图?
    Eclipse 视图
    Eclipse 菜单
    Eclipse 窗口说明
    Eclipse 修改字符集
    Eclipse 安装(Oxygen版本)
    Eclipse 教程
    jQuery 教程
    就表单验证说用户体验
    需要配置执行path?no
  • 原文地址:https://www.cnblogs.com/cute/p/2421006.html
Copyright © 2011-2022 走看看