How to find the first element of two vectors that does not match in C++

1 Answer

0 votes
#include <iostream>
#include <vector>
#include <algorithm>

using std::cout;
using std::endl;
using std::vector;

int main()
{
	vector<char> vec1{ 'a', 'b', 'b', 'w' }, vec2{ 'a', 'b', 'x', 'd' };
	std::pair<vector<char>::iterator, vector<char>::iterator> pr;

	pr = mismatch(vec1.begin(), vec1.end(), vec2.begin());

	cout << *pr.first << ' ' << *pr.second << endl;

	cout << endl;

	return 0;
}


/*
run:

b x

*/

 



answered Apr 30, 2018 by avibootz
edited Apr 30, 2018 by avibootz
...