Results 1 to 6 of 6

Thread: How can I use the mismatch() in CPP

  1. #1
    Join Date
    Dec 2009
    Posts
    28

    How can I use the mismatch() in CPP

    Hi, Everyone. I am studying in the first year of BSC- IT. I have the well knowledge of the C++ language. I can only know about the some of the built-in functions that can be defined in the C++ library. So, I want to know about the mismatch() function in C++ language. I also want to know about the use of the function mismatch() in the C++ programming. So, Can anyone help me to know about the mismatch() function.
    Last edited by Garrett; 16-02-2010 at 07:57 PM.

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Use the mismatch() in CPP

    The mismatch() function can be used to find first position of an element where the two ranges can differ. The following can be the syntax of the mismatch() function as :
    Code:
    template <class IptItrtr1, class IptItrtr2>
      pair<IptItrtr1, IptItrtr2>
        mismatch (IptItrtr1 first1, IptItrtr1 last1,
                  IptItrtr2 first2 );

  3. #3
    Join Date
    Nov 2005
    Posts
    1,323

    The mismatch()

    The following can be the program on the mismatch() function in the C++ language :
    Code:
    // mismatch algorithm example
    #include <iostream>
    #include <algorithm>
    #include <vector>
    using namespace std;
    bool mypredicate (int p, int q)
     {
      return (p==q);
    }
    int main ()
     {
      vector<int> mvctr;
      for (int p=1; p<6; p++) mvctr.pushback (p*10); 
      int myint[] = {10,20,80,320,1024};                
      pair<vector<int>::iterator,int*> mypair;
      mypair = mismatch (mvctr.begin(), mvctr.end(), myint);
      cout << "First mismatching elements: " << *mypair.first;
      cout << " and " << *mypair.second << endl;;
      mypair.fst++; mypair.second++;
      mypair = mismatch (mypair.fst, mvctr.end(), mypair.second, mprdict);
      cout << "Second mismatching elements: " << *mypair.first;
      cout << " and " << *mypair.second << endl;;
       return 0;
    }
    Output of above :
    Code:
    First mismatching elements: 30 and 80
    Second mismatching elements: 40 and 320

  4. #4
    Join Date
    Oct 2005
    Posts
    2,393

    Re: How can I use the mismatch() in CPP

    The following can be the parameters of the mismatch() function in the C++ language :
    1. fst2 : These parameters can be used in the C++ language for the forward iterator to the starting position of the sequence that can be second.
    2. fst1, lst1 : These parameters can be used in the C++ language the forward iterators to the final and starting positions of the sequence that can be first.

  5. #5
    Join Date
    May 2008
    Posts
    2,389

    The mismatch()

    Program :
    Code:
          #include <algorithm>    
          #include <functional>   
          #include <iostream>     
          #include <utility>      
          #include <vector>     
          int main ()
          {
              typedef std::vector<int, std::allocator<int> > Vector;
              typedef Vector::const_iterator Itr;
              const Vector::valuetype c1[] = { 1, 2, 3, 4 };
              const Vector::valuetype c2[] = { 1, 3, 2, 4 };
              const Vector v1 (c1 + 0, c1 + sizeof c1 / sizeof *c1);
              const Vector v2 (c2 + 0, c2 + sizeof c2 / sizeof *c2);
              std::pair<Iter, Itr> q1 =
                  std::mismatch (w1.begin (), w1.end (), w2.begin ());  
              std::pair<Iter, Itr> q2 =
                  std::mismatch (w1.begin (), w1.end (),
                                 w2.begin (), std::lessequal<int>());
              std::cout << *q1.first << ", " << *q1.second << std::endl;
              std::cout << *q2.first << ", " << *q2.second << std::endl;
              return 0;
          }
    Output:
    Code:
     2, 3
         3, 2

  6. #6
    Join Date
    Feb 2008
    Posts
    1,852

    Re: How can I use the mismatch() in CPP

    To compare an elements in the given range that can be defined by the [start1,end) to an elements that can be in a range of the same size that is starting at start2. The mismatch() function can returns the value either :
    1. If the ranges can be an equal, end1 and the corresponding element in the range second.
    2. The first location where the 2 ranges can be differ from each other.

Similar Threads

  1. Start tag/end tag mismatch error
    By raeballi in forum Windows Software
    Replies: 1
    Last Post: 25-03-2012, 01:13 PM
  2. Network Security Key Mismatch
    By Langward in forum Operating Systems
    Replies: 5
    Last Post: 13-10-2011, 04:43 PM
  3. Xonar DX channel Mismatch
    By $Agamemnon$ in forum Hardware Peripherals
    Replies: 6
    Last Post: 26-09-2010, 06:13 AM
  4. how to solve md5 sum mismatch problem
    By preetam.kondekar in forum Operating Systems
    Replies: 1
    Last Post: 23-08-2010, 12:14 PM
  5. ODBC architecture mismatch
    By Micmac in forum Windows Software
    Replies: 6
    Last Post: 21-08-2010, 06:13 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,875,350.67033 seconds with 17 queries