algorithm - STL C++

find_end()

Declaration

template <class ForwardIterator1, class ForwardIterator2>
void find_end(
	ForwardIterator1 xFirst1,
	ForwardIterator1 xLast1,
	ForwardIterator1 xFirst2,
	ForwardIterator1 xLast2
);

Description

This function finds the first set of entries in the range starting from "xFirst1" up to the entry before "xLast1" that are equal to the entries in the range from "xFirst2" up to the entry before "xLast2."

Header Include

#include <algorithm>

Overloads

template <class ForwardIterator1, class ForwardIterator2, class Predicate>
void find_end(
	ForwardIterator1 xFirst1,
	ForwardIterator1 xLast1,
	ForwardIterator1 xFirst2,
	ForwardIterator1 xLast2,
	Predicate xTest
);

Example

#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
	using namespace std;

	// Create a vector instance
	vector<char> qV;
	qV.push_back('X');
	qV.push_back('o');
	qV.push_back('a');
	qV.push_back('X');
	qV.push_back('.');
	qV.push_back('n');
	qV.push_back('e');
	qV.push_back('t');

	vector<char>::iterator qIter;
	// Output the vector
	cout << "Vector: ";
	for (qIter = qV.begin(); qIter != qV.end(); ++qIter) {
		cout << *qIter;
	}
	cout << endl;

	// Search for the range
	cout << "Searching for: ";
	for (qIter = qV.begin() + 3; qIter != qV.begin() + 5; ++qIter) {
		cout << *qIter;
	}
	cout << endl;

	qIter = find_end(qV.begin(), qV.end(), qV.begin() + 3, qV.begin() + 5);

	// Output the vector after the find
	cout << "Found entries and beyond: ";
	for (; qIter != qV.end(); ++qIter) {
		cout << *qIter;
	}
	cout << endl;

	// Keep the window open
	cin.get();
	return 0;
}

Output

find_end() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.