原文:http://www.cppblog.com/mysileng/archive/2012/12/25/196615.html 引子: 怎么对容器中的所有对象都进行同一个操作?我们可能首先想到的是用循环来实现.比如有如下的一个类: class ClxECS{public:    int DoSomething() {     cout << "Output from method DoSomething!" << endl; // 这里以输出一句话来代替具体…
例如:假设有如下的代码: class Employee { public: int DoSomething(){} } std::vector<Employee> Emps; 假设我们要调用Emps里面所包含的所有Employee的DoSomething();一般初学者会这样调用: for (std::vector<Employee>::iteror it=Emps.begin(); it!=Emps.Ends(); it++) { (*it).DoSomething(); } 而…
http://www.cnblogs.com/Purple_Xiapei/archive/2012/05/27/2520483.html STL中mem_fun和mem_fun_ref的用法 分类: C++2006-11-21 09:11 5244人阅读 评论(8) 收藏 举报 怎么对容器中的所有对象都进行同一个操作?我们可能首先想到的是用循环来实现.    比如有如下的一个类: class ClxECS{public:    int DoSomething()     {         //…
Java中的"equals"和"=="的用法及区别 在初学Java时,可能会经常碰到下面的代码: String str1 = new String("hello"); String str2 = new String("hello"); System.out.println(str1==str2); System.out.println(str1.equals(str2)); 为什么第4行和第5行的输出结果不一样?==和equ…
1.分组函数group by和Oracle中分析函数partition by的用法以及区别 2.开窗函数.…
1.引言 先看一个STL中for_each的用法: #include <iostream> #include <vector> #include <algorithm> #include <functional> #include <iterator> using namespace std; class Test { public: Test():data(_data){} void print(){cout<<"i am…
假设我们有以下的一个类: 另外有一个包含 class A 对象的数组: vector<A> vec; 如何对每一个类的对象调用成员函数print. 做法1: 利用下标 for(int i=0; i<vec.size(); ++i) { vec[i].print(); } 做法2:利用迭代器 for(vector<int>::const_iterator it=vec.begin(); it!=vec.end(); ++it) { it->print(); } 做法3:C…
STL算法 STL 提供能在各种容器中通用的算法(大约有70种),如插入.删除.查找.排序等. 许多算法操作的是容器上的一个区间(也可以是整个容器),因此需要两个参数,一个是区间起点元素的迭代器,另一个是区间终点元素的后面一个元素的迭代器.例如,排序和查找算法都需要这两个参数来指明待排序或待查找的区间. 有的算法返回一个迭代器.例如,find 算法在容器中查找一个元素,并返回一个指向该元素的迭代器. 算法可以处理容器,也可以处理普通的数组. STL 中的大部分常用算法都在头文件** algori…
本文主要是使用了STL中德map和set两个容器,使用了它们本身的一些功能函数(包括迭代器),介绍了它们的基本使用方式,是一个使用熟悉的过程. map的基本使用: #include "stdafx.h" #include<iostream> #include<set> #include<string> #include<vector> #include<map> using namespace std; int main()…
对于next_permutation函数是针对于排列组合问题的库函数,它的排序方式是按照字典的方式排列的·: 如以下代码对于next_permutation函数的初步解释: #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> using namespace std; int main() { //next_permutation()函数是基于algorithm头文…