现在的位置: 首页 > 综合 > 正文

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

2012年12月17日 ⁄ 综合 ⁄ 共 666字 ⁄ 字号 评论关闭
// equal algorithm example
#include <iostream>
#include
<algorithm>
#include
<vector>
using namespace std;

bool mypredicate (int i, int j) {
return (i==j);
}

int main () {

int myints[] = {20,40,60,80,100}; // myints: 20 40 60 80 100
vector<int>myvector (myints,myints+5); // myvector: 20 40 60 80 100

// using default comparison:
if (equal (myvector.begin(), myvector.end(), myints))
cout
<< "The contents of both sequences are equal." << endl;
else
cout
<< "The contents of both sequences differ." << endl;

myvector[
3]=81; // myvector: 20 40 60 81 100

// using predicate comparison:
if (equal (myvector.begin(), myvector.end(), myints, mypredicate))
cout
<< "The contents of both sequences are equal." << endl;
else
cout
<< "The contents of both sequences differ." << endl;

return 0;
}

抱歉!评论已关闭.