title: C++'s cin.width function explanation
body: <p>I've read this passage in the book(which barely explained) a dozen times but can't understand how this is really working. I'm trying to figure out how the functions are working.</p>
  
  <pre><code>int main() {
       int widthValue = 4;
       char sentence[ 10 ];
  
       cout &lt;&lt; "Enter a sentence:" &lt;&lt; endl;
       cin.width( 5 ); // input only 4 characters from sentence
  
       // set field width, then display characters based on that width
       while ( cin &gt;&gt; sentence )
       {
        cout.width( widthValue++ );
        cout &lt;&lt; sentence &lt;&lt; endl;
        cin.width(5); // input 5 more characters from sentence
        } // end while
        return 0;
   } // end main
  </code></pre>
  
  <p>Now the following output is produced, and here's my trouble. The first line says cin.width, and this line means that the first 4 characters, actually, will be read - namely, "This", but then you output a field width of 4, so when you execute the 'cout &lt;&lt; sentence &lt;&lt; endl statement you print 4 characters, namely - "This". After, you read 5 more characters from sentence. But I get lost on the next iteration of the loop because the width then becomes 5, yet you output "   is". I don't get the concept.</p>