title: How does the const char* and string comparison work in C++?
body: <p>Consider the following code snippet:</p>
  
  <pre><code>#include &lt;iostream&gt;
  int main() {
      std::string str = "Hello";
      const char *cstr = "Hello";
      if (cstr == str) {
          std::cout&lt;&lt;"Both are same string.";
      }
      return 0;
  }
  </code></pre>
  
  <p>I am having difficulty guessing how the const char* and string comparison work:</p>
  
  <pre><code>if (cstr == str) {
  </code></pre>
  
  <p>As per my understanding, the overloaded operator of the left operand (<strong>cstr</strong> in this case) is called with <strong>str</strong> as the argument. Now there is no overloading of <strong>==</strong> for const char*. So how does the above comparison even work?</p>
  
  <p>Had the comparison been <strong>str==cstr</strong>, I would have no issues accepting it (as == for std::string is overloaded and it accepts const char* as an argument for comparison).</p>
  
  <p>Note:- I am using gcc-4.8.1 for compiling the above code.</p>