您的位置:首页 > 理论基础 > 计算机网络

count http://www.cplusplus.com/reference/algorithm/count/

2011-07-29 22:19 447 查看
// count algorithm example
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
//count 他查找一个元素出现的次数
int main () {
int mycount;

// counting elements in array:
int myints[] = {10,20,30,30,20,10,10,20};   // 8 elements
mycount = (int) count (myints, myints+8, 10);
cout << "10 appears " << mycount << " times.\n";

// counting elements in container:
vector<int> myvector (myints, myints+8);
mycount = (int) count (myvector.begin(), myvector.end(), 20);
cout << "20 appears " << mycount  << " times.\n";

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: