title: Comparison between pointer and integer in string class - C++
body: <p>I'm new to C++.</p>
  
  <pre><code>string str = "WWWHBBB";
  if(str[mid] == "H" &amp;&amp; str[0] != "W") return; // corrected after comments for second operand
  </code></pre>
  
  <p>The above line with <code>if</code> condition gives me an error.</p>
  
  <blockquote>
    <p>Comparison between pointer and integer ('std::__1::basic_string, std::__1::allocator >::value_type' (aka 'char') and 'const char *')</p>
  </blockquote>
  
  <p>I have searched the internet enough to know that array style access is fine in strings. Error basically is pointing out comparison about pointer and integer. Really? I thought I was comparing character <code>H</code> to another character in string <code>str</code>.</p>
  
  <p>I tried if <code>str[mid]</code> really returns an iterator I should do <code>*str[mid]</code>. Nah! Didn't work either.</p>