title: How to assign value to a c++ string index by index
body: <p>How to assign value to a c++ string index by index. I have tried this code but this is not changing the value of the string. </p>
  
  <pre><code>#include &lt;iostream.h&gt;
  #include &lt;string&gt;
  
  void change(string &amp; str)
  {
      str[0] = '1';
      str[1] = '2';
      // str = "12" ; // it works but i want to assign value to each index separately. 
  }
  void main()
  {
      string str;
      change(str);
      cout &lt;&lt; str &lt;&lt; endl; // expected "12"
  }
  </code></pre>