zoukankan      html  css  js  c++  java
  • c++ 判断两个容器是否相等(equal)

    #include <iostream>     // cout
    #include <algorithm>    // equal
    #include <vector>       // 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.
    ";
        else
            cout << "The contents of both sequences differ.
    ";
        
        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.
    ";
        else
            cout << "The contents of both sequences differ.
    ";
        
        return 0;
    }

  • 相关阅读:
    Vue图片国际化
    lambda表达式
    1
    JSPday11
    JSPday10
    JSPday09
    JSPday08
    JSPday07
    JSPday23 预留
    JSPday05(Servlet)
  • 原文地址:https://www.cnblogs.com/sea-stream/p/9816414.html
Copyright © 2011-2022 走看看