📄 adjacent_find.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head> <meta name="generator" content= "HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org"> <title>adjacent_find</title> <link href="../cppreference.css" rel="stylesheet" type="text/css"></head><body><table> <tr> <td> <div class="body-content"> <div class="header-box"> <a href="../index.html">cppreference.com</a> > <a href= "index.html">C++ Algorithms</a> > <a href= "adjacent_find.html">adjacent_find</a> </div> <div class="name-format"> adjacent_find </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <algorithm> iterator adjacent_find( iterator start, iterator end ); iterator adjacent_find( iterator start, iterator end, BinPred pr );</pre> <p>The adjacent_find() function searches between <em>start</em> and <em>end</em> for two consecutive identical elements. If the binary predicate <em>pr</em> is specified, then it is used to test whether two elements are the same or not.</p> <p>The return value is an iterator that points to the first of the two elements that are found. If no matching elements are found, the returned iterator points to <em>end</em>.</p> <p>For example, the following code creates a vector containing the integers between 0 and 10 with 7 appearing twice in a row. adjacent_find() is then used to find the location of the pair of 7's:</p> <pre class="example-code"> vector<int> v1; for( int i = 0; i < 10; i++ ) { v1.push_back(i); // add a duplicate 7 into v1 if( i == 7 ) { v1.push_back(i); } } vector<int>::iterator result; result = adjacent_find( v1.begin(), v1.end() ); if( result == v1.end() ) { cout << "Did not find adjacent elements in v1" << endl; } else { cout << "Found matching adjacent elements starting at " << *result << endl; } </pre> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="find.html">find</a><br> <a href="find_end.html">find_end</a><br> <a href="find_first_of.html">find_first_of</a><br> <a href="find_if.html">find_if</a><br> <a href="unique.html">unique</a><br> <a href="unique_copy.html">unique_copy</a> </div> </div> </td> </tr> </table></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -