Created
May 7, 2014 21:17
-
-
Save Experiment5X/b4323cff09e5fdac2034 to your computer and use it in GitHub Desktop.
Example usage of std::mismatch algorithm.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
using namespace std; | |
int main(int argc, char *argv[]) | |
{ | |
vector<string> dogPeople = { "James", "Mary", "Tim", "Jane", "Greg" }; | |
vector<string> catPeople = { "James", "Mary", "Lucy", "Roger", "Sam" }; | |
// check for mismatches | |
pair<vector<string>::iterator, vector<string>::iterator> result = | |
std::mismatch(dogPeople.begin(), dogPeople.end(), catPeople.begin()); | |
// analyze the result for a mismatch | |
if (result.first == dogPeople.begin() && dogPeople.at(0) == catPeople.at(0)) | |
cout << "No mismatch" << endl; | |
else | |
cout << "Mismatch at " << (result.first - dogPeople.begin()) << ". " << *result.first << " != " << *result.second << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment