A<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FSTL_Algorithms_Non_modifying_sequence_operations%2Ffind</id>
		<title>C++/STL Algorithms Non modifying sequence operations/find - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FSTL_Algorithms_Non_modifying_sequence_operations%2Ffind"/>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B/STL_Algorithms_Non_modifying_sequence_operations/find&amp;action=history"/>
		<updated>2026-04-10T17:24:25Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://cppe.ru/index.php?title=C%2B%2B/STL_Algorithms_Non_modifying_sequence_operations/find&amp;diff=2057&amp;oldid=prev</id>
		<title> в 14:21, 25 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B/STL_Algorithms_Non_modifying_sequence_operations/find&amp;diff=2057&amp;oldid=prev"/>
				<updated>2010-05-25T14:21:06Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 14:21, 25 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://cppe.ru/index.php?title=C%2B%2B/STL_Algorithms_Non_modifying_sequence_operations/find&amp;diff=2058&amp;oldid=prev</id>
		<title>Admin: 1 версия:&amp;#32;Импорт контента...</title>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B/STL_Algorithms_Non_modifying_sequence_operations/find&amp;diff=2058&amp;oldid=prev"/>
				<updated>2010-05-25T10:28:31Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия: Импорт контента...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Demonstrating generic find algorithm with an array==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
 &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;cassert&amp;gt;&lt;br /&gt;
#include &amp;lt;algorithm&amp;gt;  // for find&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  char s[] = &amp;quot;C++ is a better C&amp;quot;;&lt;br /&gt;
  int len = strlen(s);&lt;br /&gt;
  // Search for the first occurrence of the letter e:&lt;br /&gt;
  const char* where = find(&amp;amp;s[0], &amp;amp;s[len], &amp;quot;e&amp;quot;);&lt;br /&gt;
  cout &amp;lt;&amp;lt; *where&amp;lt;&amp;lt; endl;&lt;br /&gt;
  where = find(&amp;amp;s[0], &amp;amp;s[len], &amp;quot;A&amp;quot;);&lt;br /&gt;
  cout &amp;lt;&amp;lt; *where&amp;lt;&amp;lt; endl;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
/* &lt;br /&gt;
e&lt;br /&gt;
&lt;br /&gt;
 */        &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==find and display sorted v in highest 20th percentile==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;algorithm&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;iterator&amp;gt;&lt;br /&gt;
#include &amp;lt;vector&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main( )&lt;br /&gt;
{&lt;br /&gt;
   const int a[] = { 8, 7, 4, 9, 5, 2, 6, 2, 7,9, };&lt;br /&gt;
   const int len = sizeof( a ) / sizeof( a[0] );&lt;br /&gt;
   const int percentile_20 = static_cast&amp;lt;int&amp;gt;( 0.2 * len );&lt;br /&gt;
   vector&amp;lt;int&amp;gt; v( a, a+len );&lt;br /&gt;
   copy( a, a+len, v.begin() );&lt;br /&gt;
   partial_sort( v.begin(), v.begin()+percentile_20,v.end(), greater&amp;lt;int&amp;gt;() );&lt;br /&gt;
   copy( v.begin(), v.begin()+percentile_20,ostream_iterator&amp;lt;int&amp;gt;( cout, &amp;quot; &amp;quot; ) );&lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==find and display sorted v in lowest 20th percentile==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;algorithm&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;iterator&amp;gt;&lt;br /&gt;
#include &amp;lt;vector&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main( )&lt;br /&gt;
{&lt;br /&gt;
   const int a[] = { 8, 7, 4, 9, 5, 2, 6, 2, 7,9, };&lt;br /&gt;
   const int len = sizeof( a ) / sizeof( a[0] );&lt;br /&gt;
   const int percentile_20 = static_cast&amp;lt;int&amp;gt;( 0.2 * len );&lt;br /&gt;
   vector&amp;lt;int&amp;gt; v( a, a+len );&lt;br /&gt;
   copy( a, a+len, v.begin() );&lt;br /&gt;
   partial_sort( v.begin(), v.begin()+percentile_20,v.end() );&lt;br /&gt;
   copy( v.begin(), v.begin()+percentile_20,ostream_iterator&amp;lt;int&amp;gt;( cout, &amp;quot; &amp;quot; ) );&lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==find and display v in highest 20th percentile==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;algorithm&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;iterator&amp;gt;&lt;br /&gt;
#include &amp;lt;vector&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main( )&lt;br /&gt;
{&lt;br /&gt;
   const int a[] = { 8, 7, 4, 9, 5, 2, 6, 2, 7,9, };&lt;br /&gt;
   const int len = sizeof( a ) / sizeof( a[0] );&lt;br /&gt;
   const int percentile_20 = static_cast&amp;lt;int&amp;gt;( 0.2 * len );&lt;br /&gt;
   vector&amp;lt;int&amp;gt; v( a, a+len );&lt;br /&gt;
   copy( a, a+len, v.begin() );&lt;br /&gt;
   nth_element( v.begin(), v.begin()+percentile_20-1,v.end(), greater&amp;lt;int&amp;gt;() );&lt;br /&gt;
   copy( v.begin(), v.begin() + percentile_20,ostream_iterator&amp;lt;int&amp;gt;( cout, &amp;quot; &amp;quot; ) );&lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==find and display v in lowest 20th percentile==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;algorithm&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;iterator&amp;gt;&lt;br /&gt;
#include &amp;lt;vector&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main( )&lt;br /&gt;
{&lt;br /&gt;
   const int a[] = { 8, 7, 4, 9, 5, 2, 6, 2, 7,9, };&lt;br /&gt;
   const int len = sizeof( a ) / sizeof( a[0] );&lt;br /&gt;
   const int percentile_20 = static_cast&amp;lt;int&amp;gt;( 0.2 * len );&lt;br /&gt;
   vector&amp;lt;int&amp;gt; v( a, a+len );&lt;br /&gt;
   nth_element( v.begin(), v.begin()+percentile_20-1,v.end() );&lt;br /&gt;
   copy( v.begin(), v.begin() + percentile_20,ostream_iterator&amp;lt;int&amp;gt;( cout, &amp;quot; &amp;quot; ) );&lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==find an element in a list==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
 &lt;br /&gt;
//erase an element in a list&lt;br /&gt;
//Combine erase and remove to remove a found element&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;string&amp;gt;&lt;br /&gt;
#include &amp;lt;list&amp;gt;&lt;br /&gt;
#include &amp;lt;algorithm&amp;gt;&lt;br /&gt;
#include &amp;lt;functional&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main( ) {&lt;br /&gt;
   list&amp;lt;string&amp;gt; lstStr;&lt;br /&gt;
   lstStr.push_back(&amp;quot;A&amp;quot;);&lt;br /&gt;
   lstStr.push_back(&amp;quot;B&amp;quot;);&lt;br /&gt;
   lstStr.push_back(&amp;quot;C&amp;quot;);&lt;br /&gt;
   lstStr.push_back(&amp;quot;D&amp;quot;);&lt;br /&gt;
   lstStr.push_back(&amp;quot;E&amp;quot;);&lt;br /&gt;
   list&amp;lt;string&amp;gt;::iterator p;&lt;br /&gt;
   p = find(lstStr.begin( ), lstStr.end( ), &amp;quot;C&amp;quot;);&lt;br /&gt;
   p = lstStr.erase(p);&lt;br /&gt;
   lstStr.erase(remove(lstStr.begin( ), lstStr.end( ), &amp;quot;D&amp;quot;),lstStr.end( ));&lt;br /&gt;
}&lt;br /&gt;
        &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Find the maximum element in a range in a list==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
 &lt;br /&gt;
/* The following code example is taken from the book&lt;br /&gt;
 * &amp;quot;The C++ Standard Library - A Tutorial and Reference&amp;quot;&lt;br /&gt;
 * by Nicolai M. Josuttis, Addison-Wesley, 1999&lt;br /&gt;
 *&lt;br /&gt;
 * (C) Copyright Nicolai M. Josuttis 1999.&lt;br /&gt;
 * Permission to copy, use, modify, sell and distribute this software&lt;br /&gt;
 * is granted provided this copyright notice appears in all copies.&lt;br /&gt;
 * This software is provided &amp;quot;as is&amp;quot; without express or implied&lt;br /&gt;
 * warranty, and with no claim as to its suitability for any purpose.&lt;br /&gt;
 */&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;list&amp;gt;&lt;br /&gt;
#include &amp;lt;algorithm&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    list&amp;lt;int&amp;gt; coll;&lt;br /&gt;
    list&amp;lt;int&amp;gt;::iterator pos;&lt;br /&gt;
    // insert elements from 20 to 40&lt;br /&gt;
    for (int i=20; i&amp;lt;=40; ++i) {&lt;br /&gt;
        coll.push_back(i);&lt;br /&gt;
    }&lt;br /&gt;
    /* find position of element with value 3&lt;br /&gt;
     * - there is none, so pos gets coll.end()&lt;br /&gt;
     */&lt;br /&gt;
    pos = find (coll.begin(), coll.end(),    // range&lt;br /&gt;
                3);                          // value&lt;br /&gt;
    &lt;br /&gt;
    /* reverse the order of elements between found element and the end&lt;br /&gt;
     * - because pos is coll.end() it reverses an empty range&lt;br /&gt;
     */&lt;br /&gt;
    reverse (pos, coll.end());&lt;br /&gt;
    // find positions of values 25 and 35&lt;br /&gt;
    list&amp;lt;int&amp;gt;::iterator pos25, pos35;&lt;br /&gt;
    pos25 = find (coll.begin(), coll.end(),  // range&lt;br /&gt;
                  25);                       // value&lt;br /&gt;
    pos35 = find (coll.begin(), coll.end(),  // range&lt;br /&gt;
                  35);                       // value&lt;br /&gt;
    /* print the maximum of the corresponding range&lt;br /&gt;
     * - note: including pos25 but excluding pos35&lt;br /&gt;
     */&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;max: &amp;quot; &amp;lt;&amp;lt; *max_element (pos25, pos35) &amp;lt;&amp;lt; endl;&lt;br /&gt;
    // process the elements including the last position&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;max: &amp;quot; &amp;lt;&amp;lt; *max_element (pos25, ++pos35) &amp;lt;&amp;lt; endl;&lt;br /&gt;
}&lt;br /&gt;
/* &lt;br /&gt;
max: 34&lt;br /&gt;
max: 35&lt;br /&gt;
 */&lt;br /&gt;
        &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Generic find algorithm: use find function to find an element in an array==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
 &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;cassert&amp;gt;&lt;br /&gt;
#include &amp;lt;algorithm&amp;gt;&lt;br /&gt;
#include &amp;lt;list&amp;gt;&lt;br /&gt;
#include &amp;lt;iterator&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  int a[10] = {12, 3, 25, 7, 11, 213, 7, 123, 29, -31};&lt;br /&gt;
  // Find the first element equal to 7 in the array:&lt;br /&gt;
  int* ptr = find(&amp;amp;a[0], &amp;amp;a[10], 7);&lt;br /&gt;
  assert (*ptr == 7 &amp;amp;&amp;amp; *(ptr+1) == 11);&lt;br /&gt;
  cout &amp;lt;&amp;lt; *ptr;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
/* &lt;br /&gt;
7&lt;br /&gt;
 */        &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Generic find algorithm with input iterators associated with io streams==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
 &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;cassert&amp;gt;&lt;br /&gt;
#include &amp;lt;algorithm&amp;gt;&lt;br /&gt;
#include &amp;lt;list&amp;gt;&lt;br /&gt;
#include &amp;lt;iterator&amp;gt;&lt;br /&gt;
using namespace std; &lt;br /&gt;
int main() &lt;br /&gt;
{&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Type some characters, including an &amp;quot;x&amp;quot; followed\n&amp;quot;&lt;br /&gt;
    &amp;lt;&amp;lt; &amp;quot;by at least one nonwhite-space character: &amp;quot; &amp;lt;&amp;lt; flush;&lt;br /&gt;
  istream_iterator&amp;lt;char&amp;gt; in(cin);&lt;br /&gt;
  istream_iterator&amp;lt;char&amp;gt; eos;&lt;br /&gt;
  find(in, eos, &amp;quot;x&amp;quot;);&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;The first nonwhite-space character following\n&amp;quot;&lt;br /&gt;
       &amp;lt;&amp;lt; &amp;quot;the first &amp;quot;x&amp;quot; was &amp;quot;&amp;quot; &amp;lt;&amp;lt; *(++in) &amp;lt;&amp;lt; &amp;quot;&amp;quot;.&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
  &lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
 /* &lt;br /&gt;
Type some characters, including an &amp;quot;x&amp;quot; followed&lt;br /&gt;
by at least one nonwhite-space character: x is before y&lt;br /&gt;
The first nonwhite-space character following&lt;br /&gt;
the first &amp;quot;x&amp;quot; was &amp;quot;i&amp;quot;.&lt;br /&gt;
 */       &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Locate first occurrence of a value in a vector==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
 &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using std::cout;&lt;br /&gt;
using std::endl;&lt;br /&gt;
#include &amp;lt;algorithm&amp;gt;&lt;br /&gt;
#include &amp;lt;vector&amp;gt;&lt;br /&gt;
#include &amp;lt;iterator&amp;gt;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   int a[ 10 ] = { 10, 2, 17, 5, 16, 8, 13, 11, 20, 7 };&lt;br /&gt;
   std::vector&amp;lt; int &amp;gt; v( a, a + 10 ); // copy of a&lt;br /&gt;
   std::ostream_iterator&amp;lt; int &amp;gt; output( cout, &amp;quot; &amp;quot; );&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Vector v contains: &amp;quot;;&lt;br /&gt;
   std::copy( v.begin(), v.end(), output ); // display output vector&lt;br /&gt;
   std::vector&amp;lt; int &amp;gt;::iterator location;&lt;br /&gt;
   location = std::find( v.begin(), v.end(), 16 );&lt;br /&gt;
   if ( location != v.end() ) // found 16&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;\n\nFound 16 at location &amp;quot; &amp;lt;&amp;lt; ( location - v.begin() );&lt;br /&gt;
   else // 16 not found&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;\n\n16 not found&amp;quot;;&lt;br /&gt;
   cout &amp;lt;&amp;lt; endl;&lt;br /&gt;
   return 0;&lt;br /&gt;
}&lt;br /&gt;
/* &lt;br /&gt;
Vector v contains: 10 2 17 5 16 8 13 11 20 7&lt;br /&gt;
Found 16 at location 4&lt;br /&gt;
 */&lt;br /&gt;
        &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use assert to check the find method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
 &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;cassert&amp;gt;&lt;br /&gt;
#include &amp;lt;algorithm&amp;gt;&lt;br /&gt;
#include &amp;lt;list&amp;gt;&lt;br /&gt;
#include &amp;lt;iterator&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  int a[10] = {12, 3, 25, 7, 11, 213, 7, 123, 29, -31};&lt;br /&gt;
  // Find the first element equal to 7 in the array:&lt;br /&gt;
  int* ptr = find(&amp;amp;a[0], &amp;amp;a[10], 7);&lt;br /&gt;
  assert (*ptr == 7 &amp;amp;&amp;amp; *(ptr+1) == 11);&lt;br /&gt;
  cout &amp;lt;&amp;lt; *ptr;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
/* &lt;br /&gt;
7&lt;br /&gt;
 */&lt;br /&gt;
        &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use find algorithm to find an element in a list==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
 &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;cassert&amp;gt;&lt;br /&gt;
#include &amp;lt;algorithm&amp;gt;&lt;br /&gt;
#include &amp;lt;list&amp;gt;&lt;br /&gt;
#include &amp;lt;iterator&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  int a[10] = {12, 3, 25, 7, 11, 213, 7, 123, 29, -31};&lt;br /&gt;
  list&amp;lt;int&amp;gt; list1(&amp;amp;a[0], &amp;amp;a[10]);&lt;br /&gt;
  // Find the first element equal to 7 in list1:&lt;br /&gt;
  list&amp;lt;int&amp;gt;::iterator i = find(list1.begin(),list1.end(),7);&lt;br /&gt;
  assert (*i == 7 &amp;amp;&amp;amp; *(++i) == 11);&lt;br /&gt;
  cout &amp;lt;&amp;lt; *i;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
/* &lt;br /&gt;
11&lt;br /&gt;
 */&lt;br /&gt;
        &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use find to search an element in a container==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
/* The following code example is taken from the book&lt;br /&gt;
 * &amp;quot;The C++ Standard Library - A Tutorial and Reference&amp;quot;&lt;br /&gt;
 * by Nicolai M. Josuttis, Addison-Wesley, 1999&lt;br /&gt;
 *&lt;br /&gt;
 * (C) Copyright Nicolai M. Josuttis 1999.&lt;br /&gt;
 * Permission to copy, use, modify, sell and distribute this software&lt;br /&gt;
 * is granted provided this copyright notice appears in all copies.&lt;br /&gt;
 * This software is provided &amp;quot;as is&amp;quot; without express or implied&lt;br /&gt;
 * warranty, and with no claim as to its suitability for any purpose.&lt;br /&gt;
 */&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;vector&amp;gt;&lt;br /&gt;
#include &amp;lt;deque&amp;gt;&lt;br /&gt;
#include &amp;lt;list&amp;gt;&lt;br /&gt;
#include &amp;lt;set&amp;gt;&lt;br /&gt;
#include &amp;lt;map&amp;gt;&lt;br /&gt;
#include &amp;lt;string&amp;gt;&lt;br /&gt;
#include &amp;lt;algorithm&amp;gt;&lt;br /&gt;
#include &amp;lt;iterator&amp;gt;&lt;br /&gt;
#include &amp;lt;functional&amp;gt;&lt;br /&gt;
#include &amp;lt;numeric&amp;gt;&lt;br /&gt;
/* PRINT_ELEMENTS()&lt;br /&gt;
 * - prints optional C-string optcstr followed by&lt;br /&gt;
 * - all elements of the collection coll&lt;br /&gt;
 * - separated by spaces&lt;br /&gt;
 */&lt;br /&gt;
template &amp;lt;class T&amp;gt;&lt;br /&gt;
inline void PRINT_ELEMENTS (const T&amp;amp; coll, const char* optcstr=&amp;quot;&amp;quot;)&lt;br /&gt;
{&lt;br /&gt;
    typename T::const_iterator pos;&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; optcstr;&lt;br /&gt;
    for (pos=coll.begin(); pos!=coll.end(); ++pos) {&lt;br /&gt;
        std::cout &amp;lt;&amp;lt; *pos &amp;lt;&amp;lt; &amp;quot; &amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
}&lt;br /&gt;
/* INSERT_ELEMENTS (collection, first, last)&lt;br /&gt;
 * - fill values from first to last into the collection&lt;br /&gt;
 * - NOTE: NO half-open range&lt;br /&gt;
 */&lt;br /&gt;
template &amp;lt;class T&amp;gt;&lt;br /&gt;
inline void INSERT_ELEMENTS (T&amp;amp; coll, int first, int last)&lt;br /&gt;
{&lt;br /&gt;
    for (int i=first; i&amp;lt;=last; ++i) {&lt;br /&gt;
        coll.insert(coll.end(),i);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    list&amp;lt;int&amp;gt; coll;&lt;br /&gt;
    INSERT_ELEMENTS(coll,1,9);&lt;br /&gt;
    INSERT_ELEMENTS(coll,1,9);&lt;br /&gt;
    PRINT_ELEMENTS(coll,&amp;quot;coll: &amp;quot;);&lt;br /&gt;
    // find first element with value 4&lt;br /&gt;
    list&amp;lt;int&amp;gt;::iterator pos1;&lt;br /&gt;
    pos1 = find (coll.begin(), coll.end(),    // range&lt;br /&gt;
                 4);                          // value&lt;br /&gt;
    /* find second element with value 4&lt;br /&gt;
     * - note: continue the search behind the first 4 (if any)&lt;br /&gt;
     */&lt;br /&gt;
    list&amp;lt;int&amp;gt;::iterator pos2;&lt;br /&gt;
    if (pos1 != coll.end()) {&lt;br /&gt;
        pos2 = find (++pos1, coll.end(),      // range&lt;br /&gt;
                     4);                      // value&lt;br /&gt;
    }&lt;br /&gt;
    /* print all elements from first to second 4 (both included)&lt;br /&gt;
     * - note: now we need the position of the first 4 again (if any)&lt;br /&gt;
     * - note: we have to pass the position behind the second 4 (if any)&lt;br /&gt;
     */&lt;br /&gt;
    if (pos1!=coll.end() &amp;amp;&amp;amp; pos2!=coll.end()) {&lt;br /&gt;
        copy (--pos1, ++pos2,&lt;br /&gt;
              ostream_iterator&amp;lt;int&amp;gt;(cout,&amp;quot; &amp;quot;));&lt;br /&gt;
        cout &amp;lt;&amp;lt; endl;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
/* &lt;br /&gt;
coll: 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9&lt;br /&gt;
4 5 6 7 8 9 1 2 3 4&lt;br /&gt;
 */&lt;br /&gt;
        &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use istream_iterator and find==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
 &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;        &lt;br /&gt;
#include &amp;lt;cassert&amp;gt;&lt;br /&gt;
#include &amp;lt;algorithm&amp;gt;&lt;br /&gt;
#include &amp;lt;list&amp;gt;&lt;br /&gt;
#include &amp;lt;iterator&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Type some characters, including an &amp;quot;x&amp;quot; followed\n&amp;quot;&lt;br /&gt;
    &amp;lt;&amp;lt; &amp;quot;by at least one nonwhite-space character: &amp;quot; &amp;lt;&amp;lt; flush;&lt;br /&gt;
  istream_iterator&amp;lt;char&amp;gt; in(cin);&lt;br /&gt;
  istream_iterator&amp;lt;char&amp;gt; eos;&lt;br /&gt;
  find(in, eos, &amp;quot;x&amp;quot;);&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;The first nonwhite-space character following\n&amp;quot;&lt;br /&gt;
       &amp;lt;&amp;lt; &amp;quot;the first &amp;quot;x&amp;quot; was &amp;quot;&amp;quot; &amp;lt;&amp;lt; *(++in) &amp;lt;&amp;lt; &amp;quot;&amp;quot;.&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
 /* &lt;br /&gt;
Type some characters, including an &amp;quot;x&amp;quot; followed&lt;br /&gt;
by at least one nonwhite-space character: x is after y&lt;br /&gt;
The first nonwhite-space character following&lt;br /&gt;
the first &amp;quot;x&amp;quot; was &amp;quot;i&amp;quot;.&lt;br /&gt;
 */       &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Using find with normal iteration==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
 &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;vector&amp;gt;&lt;br /&gt;
#include &amp;lt;algorithm&amp;gt; // for find&lt;br /&gt;
#include &amp;lt;iterator&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  string s(&amp;quot;It is him.&amp;quot;);&lt;br /&gt;
  vector&amp;lt;char&amp;gt; vector1(s.begin(), s.end());&lt;br /&gt;
  ostream_iterator&amp;lt;char&amp;gt; out(cout, &amp;quot; &amp;quot;);&lt;br /&gt;
  vector&amp;lt;char&amp;gt;::iterator i = find(vector1.begin(), vector1.end(), &amp;quot;i&amp;quot;);&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;chars from the first i to the end: &amp;quot;;&lt;br /&gt;
  copy(i, vector1.end(), out); cout &amp;lt;&amp;lt; endl;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
/* &lt;br /&gt;
chars from the first i to the end: i s   h i m .&lt;br /&gt;
 */        &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>