zoukankan      html  css  js  c++  java
  • C++ STL transform

    #include<iostream>
    #include<vector>
    #include <list>
    #include <algorithm>
    #include <functional>

    using namespace std;


    int main()
    {
      vector<int> vec1;
      list<int> list1;

      for (int k=0;k<10;k++)
      {
        vec1.push_back(k);
      }

      vector<int>::iterator vec_iter1;
      for (vec_iter1 = vec1.begin();vec_iter1 != vec1.end();++vec_iter1)
      {
        cout << *vec_iter1 << " ";
      }
      cout << endl;
      cout << "------------------------------------------------------" << endl;

      transform(vec1.begin(),vec1.end(),vec1.begin(),negate<int>());
      for (vec_iter1 = vec1.begin(); vec_iter1 != vec1.end(); ++vec_iter1)
      {
        cout << *vec_iter1 << " ";
      }
      cout << endl;
      cout << "------------------------------------------------------" << endl;
      
      system("pause");
      return 0;
    }

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

    0 1 2 3 4 5 6 7 8 9
    ------------------------------------------------------
    0 -1 -2 -3 -4 -5 -6 -7 -8 -9
    ------------------------------------------------------
    请按任意键继续. . .

  • 相关阅读:
    Window 7 + Ubuntu 双系统安装
    Android Proguard
    windows管理方式
    开启Telnet服务
    java中的Date类
    java中String字符串
    java自定义异常和throw、throws的使用
    java异常的嵌套和级联
    java中各种常见的异常
    java异常的基本概念和处理流程
  • 原文地址:https://www.cnblogs.com/herd/p/11007851.html
Copyright © 2011-2022 走看看