Demonstrates standard library functions equal, mismatch, lexicographical_compare. : mismatch « STL Algorithms Non modifying sequence operations « C++ Tutorial

Home
C++ Tutorial
1.Language Basics
2.Data Types
3.Operators statements
4.Array
5.Development
6.Exceptions
7.Function
8.Structure
9.Class
10.Operator Overloading
11.Pointer
12.File Stream
13.template
14.STL Introduction
15.string
16.vector
17.list
18.bitset
19.set multiset
20.valarray
21.queue stack
22.deque
23.map multimap
24.STL Algorithms Modifying sequence operations
25.STL Algorithms Non modifying sequence operations
26.STL Algorithms Binary search
27.STL Algorithms Sorting
28.STL Algorithms Merge
29.STL Algorithms Min Max
30.STL Algorithms Iterator
31.STL Algorithms Heap
32.STL Algorithms Helper
C / ANSI-C
C Tutorial
C++
Visual C++ .NET
C++ Tutorial » STL Algorithms Non modifying sequence operations » mismatch 
25.12.5.Demonstrates standard library functions equal, mismatch, lexicographical_compare.
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
   const int SIZE = 10;
   int a1SIZE 12345678910 };
   int a2SIZE 12341000678910 };
   vector< int > v1a1, a1 + SIZE ),
                 v2a1, a1 + SIZE ),
                 v3a2, a2 + SIZE );

   bool result = equalv1.begin(), v1.end(), v2.begin() );
   cout << "\n\nVector v1 " << result ? "is" "is not" 
        << " equal to vector v2.\n";

   result = equalv1.begin(), v1.end(), v3.begin() );
   cout << "Vector v1 " << result ? "is" "is not" 
        << " equal to vector v3.\n";

   pair< vector< int >::iterator,
         vector< int >::iterator > location;
   location = mismatchv1.begin(), v1.end(), v3.begin() );
   cout << "\nThere is a mismatch between v1 and v3 at "
        << "location " << location.first - v1.begin() ) 
        << "\nwhere v1 contains " << *location.first
        << " and v3 contains " << *location.second 
        << "\n\n";

   char c1SIZE "HELLO", c2SIZE "BYE BYE";

   result = lexicographical_comparec1, c1 + SIZE, c2, c2 + SIZE );
   cout << c1 
        << result ? " is less than " " is greater than " )
        << c2;

   cout << endl;
   return 0;
}
25.12.mismatch
25.12.1.Generic mismatch algorithm: Find the corresponding positions in a deque and list at which unequal elements first occur
25.12.2.Check for mismatch between two vectors
25.12.3.Use mismatch function to find the first match
25.12.4.Use mismatch function with custom function
25.12.5.Demonstrates standard library functions equal, mismatch, lexicographical_compare.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.