title: formatting phone number in c++
body: <p>Please assist, I am trying to format a phone number like <code>(111)111-1111</code>. I have the following code which works but I would like to write much shorter. </p>
  
  <pre><code>int main(){
  
      string phone_number;
  
      cin &gt;&gt; phone_number;
      cout&lt;&lt;"(";
  
      for(int i = 0; i &lt; 3; i++) {
        cout &lt;&lt; phone_number[i];
      }
  
      cout &lt;&lt; ")";
      for(int i = 3; i &lt; 6; i++) {
        cout &lt;&lt; phone_number[i];
      }
  
      cout &lt;&lt; "-";
  
      for(int i = 6; i &lt; 10; i++) {
        cout &lt;&lt; phone_number[i];
      }
  
      cout&lt;&lt;endl;
      return 0;
  }
  </code></pre>
  
  <p>please assist</p>