Chinaunix首页 | 论坛 | 博客
  • 博客访问: 449187
  • 博文数量: 80
  • 博客积分: 2301
  • 博客等级: 大尉
  • 技术积分: 884
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-16 20:07
个人简介

I\'m interested in mathematics and Daoism. Welcome to talk about these subjects with me.

文章分类

全部博文(80)

文章存档

2017年(2)

2016年(16)

2015年(4)

2014年(6)

2013年(22)

2012年(2)

2011年(1)

2010年(4)

2009年(20)

2008年(2)

2007年(1)

我的朋友

分类: C/C++

2016-08-23 09:49:41


点击(此处)折叠或打开

  1. #include <stdio.h>
  2. #include <vector>
  3. #include <string>
  4. #include <algorithm>
  5. #include <iostream>

  6. using namespace std;

  7. class not_contain {
  8.     private:
  9.         string key;

  10.     public:
  11.         not_contain (string k)
  12.         {
  13.             key = k;
  14.         }

  15.         bool operator()(const string &x) const
  16.         {
  17.             return x.find(key) == string::npos && x.find(key) == string::npos;
  18.         }

  19. };

  20. int main(int argc, char* argv[])
  21. {
  22.     vector<string> a;

  23.     a.push_back("a");
  24.     a.push_back("ab");
  25.     a.push_back("de");
  26.     a.push_back("ea");
  27.     a.push_back("bb");

  28.     vector<string>::iterator it;
  29.     size_t i = 0;

  30.     /*
  31.     for(it = a.begin(); it != a.end(); it++)
  32.         cout << (*it)<<endl;
  33.     cout<<endl;
  34.     */
  35.     for(; i < a.size(); i++)
  36.     {
  37.         string &s = a[i];
  38.         printf("i = %ld\t%s\n", i, s.c_str());
  39.     }

  40.     vector<string>::iterator last = remove_if(a.begin(), a.end(), not_contain("a"));
  41.     printf("\nelements before last:\n");
  42.     for(it = a.begin(); it != last; it++)
  43.         cout<<(*it)<<endl;

  44.     a.erase(last, a.end());

  45.     printf("\nelements after erase:\n");
  46.     for(i = 0; i < a.size(); i++)
  47.     {
  48.         string &s = a[i];
  49.         printf("i = %ld\t%s\n", i, s.c_str());
  50.     }
  51.     printf("\n");

  52.     return 0;
  53. };

阅读(1043) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~