使用STL库sort函数对vector进行排序,vector的内容为对象的指针,而不是对象. 代码如下 #include <stdio.h> #include <vector> #include <algorithm> using namespace std; class Elm { public: int m_iSortProof; private: int __m_iValue; static int __m_iCnt; public: Elm(); int get
一.unique函数 类属性算法unique的作用是从输入序列中"删除"全部相邻的反复元素. 该算法删除相邻的反复元素.然后又一次排列输入范围内的元素,而且返回一个迭代器(容器的长度没变,仅仅是元素顺序改变了),表示无反复的值范围得结束. // sort words alphabetically so we can find the duplicates sort(words.begin(), words.end()); /* eliminate duplicate words: *
预定义函数对象和函数适配器 预定义函数对象基本概念:标准模板库STL提前定义了很多预定义函数对象,#include <functional> 必须包含. 1使用预定义函数对象: void main() { plus<int> intAdd; int x = 10; int y = 20; int z = intAdd(x, y); //等价于 x + y cout << z << endl; plus<string> stringAdd; str