title: check if string starts with another string: find or compare?
body: <p>If you want to know if a string starts with another, how would you do that in C++/STL? In Java there is <code>String.startsWith</code>, Python also has <code>string.startwith</code>, STL does not have a direct method for it. Instead, there are <code>std::string::find</code> and <code>std::string::compare</code>. Until now I used both methods, mostly depending on my current mood:</p>
  
  <pre><code>if ( str1.compare( 0, str2.length(), str2 ) == 0 )
      do_something();
  if ( str1.find(str2) == 0 )
      do_something();
  </code></pre>
  
  <p>Of course, you could also do <code>str.substr(0,str2.length()) == str2</code>, maybe there are still some other ways do achieve the same. <code>find</code> is a bit handier than <code>compare</code>, but I have seen more people recommending <code>compare</code> that <code>find</code>.</p>
  
  <p>But which one is <em>preferred</em>? Is there a performance difference? Is it implementation-dependent (GCC, VC++, etc)?</p>