• 顺序容器删除元素 vector list deque


    #include <iostream>
    #include <list>
    #include <algorithm>
    #include <string>

    using namespace std;

    int main()
    {
      list<string> slist;
      slist.push_back("A");
      slist.push_back("B");
      slist.push_back("C");
      slist.push_back("D");
      slist.push_back("E");
      slist.push_back("F");
      slist.push_back("G");

      list<string>::iterator iter;
      for (iter=slist.begin();iter != slist.end();++iter)
      {
        cout << *iter<< endl;
      }

      cout << "---------------------------------------" << endl;

      string s1("D");
      string s2("F");
      list<string>::iterator iter_start = find(slist.begin(),slist.end(),s1);
      list<string>::iterator iter_end = find(slist.begin(), slist.end(), s2);

      if (iter_start != slist.end() && iter_end != slist.end())
      {
        slist.erase(iter_start,iter_end);
      }

      cout << "---------------------------------------" << endl;
      list<string>::iterator iter2;
      for (iter2 = slist.begin(); iter2 != slist.end(); ++iter2)
      {
        cout << *iter2 << endl;
      }
      cout << "---------------------------------------" << endl;


      system("pause");
      return 0;
    }

    =======================================================

    A
    B
    C
    D
    E
    F
    G
    ---------------------------------------
    ---------------------------------------
    A
    B
    C
    F
    G
    ---------------------------------------
    请按任意键继续. . .

  • 相关阅读:
    iOS 整理面试题(上)
    2021年十大白马名单
    RabbitMQ:消息重复消费
    RabbitMQ:保证消息的顺序性
    RabbitMQ:保证消息的可靠性传输
    AWS S3 大文件分片上传
    rebase 用法小结
    Flask at scale
    MySQL分区
    动态规划示例题
  • 原文地址:https://www.cnblogs.com/herd/p/10993720.html
Copyright © 2020-2023  润新知