title: match a short string within a long string in c++
body: <p>I tried to write a class called <code>Mystring</code> which basically does everything std::string class can do. Right now I'm trying to write a <code>MyString::rfind</code> function which will match a short string with the long string(just like the <code>rfind</code> function for string class). However, when I run the code nothing gets printed out in the console. Can anyone spot where the problem is?</p>
  <pre><code>//cpp 
  size_t MyString::rfind(const MyString&amp; str, size_t pos) const {
      if (str.size() == 0 &amp;&amp; pos &lt; s.size()) { return pos; }
      if (str.size() == 0 &amp;&amp; pos &gt; (s.size() - 1) ) { return s.size(); }
      size_t a = std::min(pos, (s.size() - 1));
      for (size_t i = a; i &gt;= 0; --i) {
          if (s[a] == str.s[0]) {
              for (size_t b = 1; b &lt; str.size(); ++b) {
                  if (s[i + b] != str.s[b]) { break; }
                  if (b == (str.size() - 1)) { return i; }
              }
              return -1;
          }
  
      }
      return -1;
  }
  
  
  //main
  int main(){
   
  const MyString testMyString = &quot;0123456789&quot;;
  cout &lt;&lt; testMyString.rfind(&quot;647&quot;)&lt;&lt; endl;
  return 0;
  }
  </code></pre>