Find the first element in the range (first, last + 1) that matches value : Algorithm « vector « 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 » vector » Algorithm 
16.32.13.Find the first element in the range (first, last + 1) that matches value
#include <iostream>
#include <algorithm>

using namespace std ;

int main(void)
 {
   const int ARRAY_SIZE = 8;
   int IntArray[ARRAY_SIZE1234456};
   int *location ;  //stores the position of the first matching element.
   int i;
   int value = 4;

   // print content of IntArray
   for (i = 0; i < ARRAY_SIZE; i++)
     cout << IntArray[i<< ", ";

   //Find the first element in the range (first, last + 1) that matches value.
   location = find(IntArray, IntArray + ARRAY_SIZE, value);
   
   //print the matching element if any was found
   if (location != IntArray + ARRAY_SIZE)  
     cout << "First element that matches " << value << " is at location "
     << (location - IntArray<< endl;
   else                    
     cout << "The sequence does not contain any elements with value " << value << endl;
}
16.32.Algorithm
16.32.1.Using the for_each() Algorithm
16.32.2.find_if, bind2nd and greater_equal
16.32.3.Mutating Sequence Algorithm
16.32.4.Use the count_if algorithm with the unary predicate IsEven
16.32.5.Use count to determine the number of '0's in the vector
16.32.6.merge the elements of NumbersVestor and NumbersList and place the results in NumbersDeque
16.32.7.shuffle the elements in a random order
16.32.8.Fill elements in a vector with custom generator
16.32.9.random number generation in quantitative finance
16.32.10.Inner product of a vector and another vector
16.32.11.The adjacent difference of the vector
16.32.12.for_each element in a vector apply custom function
16.32.13.Find the first element in the range (first, last + 1) that matches value
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.