A<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B_Tutorial%2Fstring%2Fstring_find</id>
		<title>C++ Tutorial/string/string find - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B_Tutorial%2Fstring%2Fstring_find"/>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B_Tutorial/string/string_find&amp;action=history"/>
		<updated>2026-04-18T06:07:59Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C%2B%2B_Tutorial/string/string_find&amp;diff=2763&amp;oldid=prev</id>
		<title> в 14:21, 25 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B_Tutorial/string/string_find&amp;diff=2763&amp;oldid=prev"/>
				<updated>2010-05-25T14:21:17Z</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://www.cppe.ru/index.php?title=C%2B%2B_Tutorial/string/string_find&amp;diff=2764&amp;oldid=prev</id>
		<title>Admin: 1 версия:&amp;#32;Импорт контента...</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B_Tutorial/string/string_find&amp;diff=2764&amp;oldid=prev"/>
				<updated>2010-05-25T10:30:27Z</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;==find first occurrence of a character - equivalent of strchr()==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;string&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main( )&lt;br /&gt;
{&lt;br /&gt;
   string typing( &amp;quot;The quick, brown fox jumps over the lazy dog&amp;quot; );&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;String:  &amp;quot; &amp;lt;&amp;lt; typing &amp;lt;&amp;lt; endl;&lt;br /&gt;
   // find first occurrence of a character - equivalent of strchr()&lt;br /&gt;
   string::size_type index = typing.find( &amp;quot;u&amp;quot; );&lt;br /&gt;
   if( index != string::npos )&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;\nThe first \&amp;quot;u\&amp;quot; is at index &amp;quot; &amp;lt;&amp;lt; index;&lt;br /&gt;
   else&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;\nThere is no \&amp;quot;u\&amp;quot; in the string&amp;quot;;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==find first occurrence of a substring - equivalent of strstr()==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;string&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main( )&lt;br /&gt;
{&lt;br /&gt;
   string typing( &amp;quot;The quick, brown fox jumps over the lazy dog&amp;quot; );&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;String:  &amp;quot; &amp;lt;&amp;lt; typing &amp;lt;&amp;lt; endl;&lt;br /&gt;
&lt;br /&gt;
   // find first occurrence of a substring - equivalent of strstr()&lt;br /&gt;
   string::size_type index = typing.find( &amp;quot;fox&amp;quot; );&lt;br /&gt;
   if( index != string::npos )&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;\n\&amp;quot;fox\&amp;quot; first occurs at index &amp;quot; &amp;lt;&amp;lt; index;&lt;br /&gt;
   else&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;\n\&amp;quot;fox\&amp;quot; is not in the string&amp;quot;;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Find first out of==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;  &lt;br /&gt;
  #include &amp;lt;string&amp;gt;  &lt;br /&gt;
  using namespace std;  &lt;br /&gt;
    &lt;br /&gt;
  int main()  {  &lt;br /&gt;
     string s1 = &amp;quot;this is a test&amp;quot;;  &lt;br /&gt;
     int n;  &lt;br /&gt;
    &lt;br /&gt;
     n = s1.find_first_not_of(&amp;quot;aeiouAEIOU&amp;quot;);  &lt;br /&gt;
     cout &amp;lt;&amp;lt; &amp;quot;First consonant at &amp;quot; &amp;lt;&amp;lt; n &amp;lt;&amp;lt; endl;  &lt;br /&gt;
     return 0;  &lt;br /&gt;
  }&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==find last occurrence of a character - equivalent of strrchr()==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;string&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main( )&lt;br /&gt;
{&lt;br /&gt;
   string typing( &amp;quot;The quick, brown fox jumps over the lazy dog&amp;quot; );&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;String:  &amp;quot; &amp;lt;&amp;lt; typing &amp;lt;&amp;lt; endl;&lt;br /&gt;
 &lt;br /&gt;
   // find last occurrence of a character - equivalent of strrchr()&lt;br /&gt;
   string::size_type index = typing.rfind( &amp;quot;u&amp;quot; );&lt;br /&gt;
   if( index != string::npos )&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;\nThe last \&amp;quot;u\&amp;quot; is at index &amp;quot; &amp;lt;&amp;lt; index;&lt;br /&gt;
   else&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;\nThere is no \&amp;quot;u\&amp;quot; in the string&amp;quot;;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==find last occurrence of a substring - no C-string equivalent==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;string&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main( )&lt;br /&gt;
{&lt;br /&gt;
   string typing( &amp;quot;The quick, brown fox jumps over the lazy dog&amp;quot; );&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;String:  &amp;quot; &amp;lt;&amp;lt; typing &amp;lt;&amp;lt; endl;&lt;br /&gt;
   // find last occurrence of a substring - no C-string equivalent&lt;br /&gt;
   string::size_type index = typing.rfind( &amp;quot;fox&amp;quot; );&lt;br /&gt;
   if( index != string::npos )&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;\n\&amp;quot;fox\&amp;quot; last occurs at index &amp;quot; &amp;lt;&amp;lt; index;&lt;br /&gt;
   else&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;\n\&amp;quot;fox\&amp;quot; is not in the string&amp;quot;;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Find the first occurance==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;  &lt;br /&gt;
  #include &amp;lt;string&amp;gt;  &lt;br /&gt;
  using namespace std;  &lt;br /&gt;
    &lt;br /&gt;
  int main()  {  &lt;br /&gt;
     string s1 = &amp;quot;this is a test&amp;quot;;  &lt;br /&gt;
     int n;  &lt;br /&gt;
    &lt;br /&gt;
     n = s1.find_first_of(&amp;quot;is&amp;quot;);  &lt;br /&gt;
     cout &amp;lt;&amp;lt; n &amp;lt;&amp;lt; endl;  &lt;br /&gt;
    &lt;br /&gt;
     return 0;  &lt;br /&gt;
  }&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Find the first of any of these chars==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;string&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
int main( ) {&lt;br /&gt;
   std::string s = &amp;quot;Search from the beginning&amp;quot;;&lt;br /&gt;
   std::cout &amp;lt;&amp;lt; s.find_first_of(&amp;quot;swi&amp;quot;)           // Find the first of any of these chars&lt;br /&gt;
             &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;                            &lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;19&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Find the first of any of these chars starting from the end==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;string&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
int main( ) {&lt;br /&gt;
   std::string s = &amp;quot;Search from the beginning&amp;quot;;&lt;br /&gt;
   std::cout &amp;lt;&amp;lt; s.find_last_of(&amp;quot;abg&amp;quot;) &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;   // Find the first of any of these chars starting from the end&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;24&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Find the first that&amp;quot;s not in this set==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;string&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
int main( ) {&lt;br /&gt;
   std::string s = &amp;quot;Search from the beginning&amp;quot;;&lt;br /&gt;
   std::cout &amp;lt;&amp;lt; s.find_first_not_of(&amp;quot;the&amp;quot;)   // Find the first that&amp;quot;s not in this set&lt;br /&gt;
             &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;                            // &lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Find the first that&amp;quot;s not in this set, starting from the end==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;string&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
int main( ) {&lt;br /&gt;
   std::string s = &amp;quot;Search from the beginning&amp;quot;;&lt;br /&gt;
   std::cout &amp;lt;&amp;lt; s.find_last_not_of(&amp;quot;from&amp;quot;)     // Find the first that&amp;quot;s not in this set, starting from the end&lt;br /&gt;
             &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;24&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==search a sub string==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;string&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  int i;&lt;br /&gt;
  string s1 =&amp;quot;this is a test.&amp;quot;;&lt;br /&gt;
  string s2;&lt;br /&gt;
  i = s1.find(&amp;quot;is&amp;quot;);&lt;br /&gt;
  if(i!=string::npos) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Match found at &amp;quot; &amp;lt;&amp;lt; i &amp;lt;&amp;lt; endl;&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Remaining string is:\n&amp;quot;;&lt;br /&gt;
    s2.assign(s1, i, s1.size());&lt;br /&gt;
    cout &amp;lt;&amp;lt; s2;&lt;br /&gt;
  }&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;\n\n&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
  return 0;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Match found at 2&lt;br /&gt;
Remaining string is:&lt;br /&gt;
is is a test.&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Search from the beginning==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;string&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
int main( ) {&lt;br /&gt;
   std::string s = &amp;quot;Search from the beginning&amp;quot;;&lt;br /&gt;
   std::cout &amp;lt;&amp;lt; s.find(&amp;quot;ar&amp;quot;) &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;            // Search from the beginning&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Search from the end==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;string&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
int main( ) {&lt;br /&gt;
   std::string s = &amp;quot;Search from the beginning&amp;quot;;&lt;br /&gt;
   std::cout &amp;lt;&amp;lt; s.rfind(&amp;quot;ar&amp;quot;) &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;           // Search from the end&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Searching for the first occurrence of a letter in a string==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;string&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
void showresult(string s, string::size_type i);&lt;br /&gt;
int main(){&lt;br /&gt;
  string::size_type indx;&lt;br /&gt;
  string str(&amp;quot;one two three, one two three&amp;quot;);&lt;br /&gt;
  string str2;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Searching for the first occurrence of t or h\n&amp;quot;;&lt;br /&gt;
  indx = str.find_first_of(&amp;quot;th&amp;quot;);&lt;br /&gt;
  showresult(str, indx);&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
// Display the results of the search.&lt;br /&gt;
void showresult(string s, string::size_type i) {&lt;br /&gt;
  if(i == string::npos) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;No match found.\n&amp;quot;;&lt;br /&gt;
    return;&lt;br /&gt;
  }&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Match found at index &amp;quot; &amp;lt;&amp;lt; i &amp;lt;&amp;lt; endl;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Remaining string from point of match: &amp;quot;&lt;br /&gt;
       &amp;lt;&amp;lt; s.substr(i) &amp;lt;&amp;lt; &amp;quot;\n\n&amp;quot;;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Searching for the first occurrence of any character other than o, n, e, or space==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;string&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
void showresult(string s, string::size_type i);&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  string::size_type indx;&lt;br /&gt;
  string str(&amp;quot;one two three, one two three&amp;quot;);&lt;br /&gt;
  string str2;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Searching for the first occurrence of any character other than o, n, e, or space\n&amp;quot;;&lt;br /&gt;
  indx = str.find_first_not_of(&amp;quot;one &amp;quot;);&lt;br /&gt;
  showresult(str, indx);&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
// Display the results of the search.&lt;br /&gt;
void showresult(string s, string::size_type i) {&lt;br /&gt;
  if(i == string::npos) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;No match found.\n&amp;quot;;&lt;br /&gt;
    return;&lt;br /&gt;
  }&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Match found at index &amp;quot; &amp;lt;&amp;lt; i &amp;lt;&amp;lt; endl;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Remaining string from point of match: &amp;quot;&lt;br /&gt;
       &amp;lt;&amp;lt; s.substr(i) &amp;lt;&amp;lt; &amp;quot;\n\n&amp;quot;;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Searching for the first occurrence of a substring in a string==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;string&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
void showresult(string s, string::size_type i);&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  string::size_type indx;&lt;br /&gt;
  string str(&amp;quot;one two three, one two three&amp;quot;);&lt;br /&gt;
  string str2;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Searching for the first occurrence of &amp;quot;two&amp;quot;\n&amp;quot;;&lt;br /&gt;
  indx = str.find(&amp;quot;two&amp;quot;);&lt;br /&gt;
  showresult(str, indx);&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
// Display the results of the search.&lt;br /&gt;
void showresult(string s, string::size_type i) {&lt;br /&gt;
  if(i == string::npos) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;No match found.\n&amp;quot;;&lt;br /&gt;
    return;&lt;br /&gt;
  }&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Match found at index &amp;quot; &amp;lt;&amp;lt; i &amp;lt;&amp;lt; endl;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Remaining string from point of match: &amp;quot;&lt;br /&gt;
       &amp;lt;&amp;lt; s.substr(i) &amp;lt;&amp;lt; &amp;quot;\n\n&amp;quot;;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Searching for the last occurrence of a letter in a string==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;string&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
void showresult(string s, string::size_type i);&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  string::size_type indx;&lt;br /&gt;
  string str(&amp;quot;one two three, one two three&amp;quot;);&lt;br /&gt;
  string str2;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Searching for the last occurrence of t or h\n&amp;quot;;&lt;br /&gt;
  indx = str.find_last_of(&amp;quot;th&amp;quot;);&lt;br /&gt;
  showresult(str, indx);&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
// Display the results of the search.&lt;br /&gt;
void showresult(string s, string::size_type i) {&lt;br /&gt;
  if(i == string::npos) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;No match found.\n&amp;quot;;&lt;br /&gt;
    return;&lt;br /&gt;
  }&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Match found at index &amp;quot; &amp;lt;&amp;lt; i &amp;lt;&amp;lt; endl;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Remaining string from point of match: &amp;quot;&lt;br /&gt;
       &amp;lt;&amp;lt; s.substr(i) &amp;lt;&amp;lt; &amp;quot;\n\n&amp;quot;;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Searching for the last occurrence of any character other than o, n, e, or space==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;string&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
void showresult(string s, string::size_type i);&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  string::size_type indx;&lt;br /&gt;
  string str(&amp;quot;one two three, one two three&amp;quot;);&lt;br /&gt;
  string str2;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Searching for the last occurrence of any character other than o, n, e, or space\n&amp;quot;;&lt;br /&gt;
  indx = str.find_last_not_of(&amp;quot;one &amp;quot;);&lt;br /&gt;
  showresult(str, indx);&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
// Display the results of the search.&lt;br /&gt;
void showresult(string s, string::size_type i) {&lt;br /&gt;
  if(i == string::npos) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;No match found.\n&amp;quot;;&lt;br /&gt;
    return;&lt;br /&gt;
  }&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Match found at index &amp;quot; &amp;lt;&amp;lt; i &amp;lt;&amp;lt; endl;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Remaining string from point of match: &amp;quot;&lt;br /&gt;
       &amp;lt;&amp;lt; s.substr(i) &amp;lt;&amp;lt; &amp;quot;\n\n&amp;quot;;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Searching for the last occurrence of a substring in a string==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;string&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
void showresult(string s, string::size_type i);&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  string::size_type indx;&lt;br /&gt;
  string str(&amp;quot;one two three, one two three&amp;quot;);&lt;br /&gt;
  string str2;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Searching for the last occurrence of &amp;quot;two&amp;quot;\n&amp;quot;;&lt;br /&gt;
  indx = str.rfind(&amp;quot;two&amp;quot;);&lt;br /&gt;
  showresult(str, indx);&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
// Display the results of the search.&lt;br /&gt;
void showresult(string s, string::size_type i) {&lt;br /&gt;
  if(i == string::npos) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;No match found.\n&amp;quot;;&lt;br /&gt;
    return;&lt;br /&gt;
  }&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Match found at index &amp;quot; &amp;lt;&amp;lt; i &amp;lt;&amp;lt; endl;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Remaining string from point of match: &amp;quot;&lt;br /&gt;
       &amp;lt;&amp;lt; s.substr(i) &amp;lt;&amp;lt; &amp;quot;\n\n&amp;quot;;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==string.find_first_not_of( substring )==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;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;string&amp;gt;&lt;br /&gt;
using std::string;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   string string1( &amp;quot;This is a test string!&amp;quot;);&lt;br /&gt;
   int location;&lt;br /&gt;
   &lt;br /&gt;
   location = string1.find_first_not_of( &amp;quot;is&amp;quot; );&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;\n\n(find_first_not_of) &amp;quot;&amp;quot; &amp;lt;&amp;lt; string1[ location ]&lt;br /&gt;
      &amp;lt;&amp;lt; &amp;quot; &amp;quot; &amp;lt;&amp;lt; location;&lt;br /&gt;
   return 0;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;(find_first_not_of) &amp;quot;T 0&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==string.find_first_of( substring )==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;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;string&amp;gt;&lt;br /&gt;
using std::string;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   string string1( &amp;quot;This is a test string!&amp;quot;);&lt;br /&gt;
   int location;&lt;br /&gt;
   &lt;br /&gt;
   location = string1.find_first_of( &amp;quot;is&amp;quot; );&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;\n\n(find_first_of) found &amp;quot;&amp;quot; &amp;lt;&amp;lt; string1[ location ]&lt;br /&gt;
      &amp;lt;&amp;lt; &amp;quot;at: &amp;quot; &amp;lt;&amp;lt; location;&lt;br /&gt;
   return 0;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;(find_first_of) found &amp;quot;iat: 2&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==string.find_last_of(substring)==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;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;string&amp;gt;&lt;br /&gt;
using std::string;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   string string1( &amp;quot;This is a test string!&amp;quot;);&lt;br /&gt;
   int location;&lt;br /&gt;
   &lt;br /&gt;
   location = string1.find_last_of( &amp;quot;is&amp;quot; );&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;\n\n(find_last_of) found &amp;quot;&amp;quot; &amp;lt;&amp;lt; string1[ location ] &lt;br /&gt;
        &amp;lt;&amp;lt; &amp;quot; at: &amp;quot; &amp;lt;&amp;lt; location;&lt;br /&gt;
        &lt;br /&gt;
   return 0;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;(find_last_of) found &amp;quot;i at: 18&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==string.find(substring)==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;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;string&amp;gt;&lt;br /&gt;
using std::string;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   string string1( &amp;quot;This is a test string!&amp;quot;);&lt;br /&gt;
   int location;&lt;br /&gt;
   &lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Original string:\n&amp;quot; &amp;lt;&amp;lt; string1 &lt;br /&gt;
        &amp;lt;&amp;lt; &amp;quot;\n\n(find) \&amp;quot;is\&amp;quot; was found at: &amp;quot; &amp;lt;&amp;lt; string1.find( &amp;quot;is&amp;quot; ); &lt;br /&gt;
        &lt;br /&gt;
   return 0;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Original string:&lt;br /&gt;
This is a test string!&lt;br /&gt;
(find) &amp;quot;is&amp;quot; was found at: 2&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==string.rfind(substring)==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;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;string&amp;gt;&lt;br /&gt;
using std::string;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   string string1( &amp;quot;This is a test string!&amp;quot;);&lt;br /&gt;
   int location;&lt;br /&gt;
   &lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Original string:\n&amp;quot; &amp;lt;&amp;lt; string1 &lt;br /&gt;
        &amp;lt;&amp;lt; &amp;quot;\n\n(find) \&amp;quot;is\&amp;quot; was found at: &amp;quot; &amp;lt;&amp;lt; string1.rfind( &amp;quot;is&amp;quot; ); &lt;br /&gt;
        &lt;br /&gt;
   return 0;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Original string:&lt;br /&gt;
This is a test string!&lt;br /&gt;
(find) &amp;quot;is&amp;quot; was found at: 5&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Using find with reverse iteration==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;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;
&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;chars from the last t to the beginning: &amp;quot;;&lt;br /&gt;
  vector&amp;lt;char&amp;gt;::reverse_iterator r = find(vector1.rbegin(), vector1.rend(), &amp;quot;t&amp;quot;&lt;br /&gt;
);&lt;br /&gt;
  copy(r, vector1.rend(), out); cout &amp;lt;&amp;lt; endl;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;chars from the last t to the end: &amp;quot;;&lt;br /&gt;
  copy(r.base() - 1, vector1.end(), out); cout &amp;lt;&amp;lt; endl;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;chars from the last t to the beginning: t I&lt;br /&gt;
chars from the last t to the end: t   i s   h i m .&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>