www.easyCPlusPlus.com

Easy C++

www.easyCPlusPlus.com

STL Tutorial - Lesson 6: Generic Algorithms, Part 2

includes

by John Kopp

Support this site at no cost to you

Algorithm includes
Include file <algorithm>
Use Test whether one sorted range contains all the elements of another sorted range.

#include <vector>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;

int main() {

    vector<string> v1, v2;

    v1.push_back("A");
    v1.push_back("noble");
    v1.push_back("spirit");
    v1.push_back("embiggens");
    v1.push_back("the");
    v1.push_back("smallest");
    v1.push_back("man");

    v2.push_back("the");
    v2.push_back("smallest");
    v2.push_back("man");

    bool found = includes(v1.begin(), v1.end(), v2.begin(), v2.end());

    if (found) {
        cout << "v2 found within v1" << endl;
    }

    return 0;

}

OUTPUT:
v2 found within v1

 

Previous Page       Next Page