zoukankan      html  css  js  c++  java
  • 顺序容器删除元素 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
    ---------------------------------------
    请按任意键继续. . .

  • 相关阅读:
    回答提出的问题1-17章
    《构建之法》第13-17章读书笔记
    读《一个程序员的生命周期》有感
    构建之法的第十、十一、十二章读书笔记
    阅读《构建之法》第8,9,10章
    5.2-5.3
    作业5.1测试与封装
    读《构建之法》5.6.7 思考
    读《构建之法》的思考
    作业2 结对思则运算
  • 原文地址:https://www.cnblogs.com/herd/p/10993720.html
Copyright © 2011-2022 走看看