title: Why does the size of this std::string change, when characters are changed?
body: <p>I have an issue in which the size of the string is effected with the presence of a <code>'\0'</code> character. I searched all over in SO and could not get the answer still.</p>
  
  <p>Here is the snippet.</p>
  
  <pre><code>int main()
  {
    std::string a = "123123\0shai\0";
    std::cout &lt;&lt; a.length();
  }
  </code></pre>
  
  <p><a href="http://ideone.com/W6Bhfl" rel="nofollow noreferrer">http://ideone.com/W6Bhfl</a></p>
  
  <p>The output in this case is </p>
  
  <pre><code>6
  </code></pre>
  
  <p>Where as the same program with a different string having numerals instead of characters</p>
  
  <pre><code>int main()
  {
    std::string a = "123123\0123\0";
    std::cout &lt;&lt; a.length();
  }
  </code></pre>
  
  <p><a href="http://ideone.com/mtfS50" rel="nofollow noreferrer">http://ideone.com/mtfS50</a></p>
  
  <p>gives an output of </p>
  
  <pre><code>8
  </code></pre>
  
  <p>What exactly is happening under the hood? How does presence of a <code>'\0'</code> character change the behavior?</p>