title: C++ strings why cant be used as char arrays?
body: <pre><code>int main()
  {    
      string a;
  
      a[0] = '1';
      a[1] = '2';
      a[2] = '\0';
  
      cout &lt;&lt; a;
  }
  </code></pre>
  
  <p>Why doesn't this code work? Why is it not printing the string?</p>