title: Is it bad to depend on index 0 of an empty std::string?
body: <pre><code>std::string my_string = "";
  char test = my_string[0];
  </code></pre>
  
  <p>I've noticed that this doesn't crash, and every time I've tested it, test is 0.</p>
  
  <p>Can I depend on it always being 0? or is it arbitrary?</p>
  
  <p>Is this bad programming?</p>
  
  <p>Edit:
  From some comments, I gather that there is some misunderstanding about the usefulness of this.</p>
  
  <p>The purpose of this is NOT to check to see if the string is empty.
  It is to not need to check whether the string is empty.</p>
  
  <p>The situation is that there is a string that may or may not be empty.
  I only care about the first character of this string (if it is not empty).</p>
  
  <p>It seems to me, it would be less efficient to check to see if the string is empty, and then, if it isn't empty, look at the first character.</p>
  
  <pre><code>if (! my_string.empty())
      test = my_string[0];
  else
      test = 0;
  </code></pre>
  
  <p>Instead, I can just look at the first character without needing to check to see if the string is empty.</p>
  
  <pre><code>test = my_string[0];
  </code></pre>