title: Using cin in C++ with Width() to avoid buffer overflow
body: <p>Here is an easy question.  I wrote this C++ code:</p>
  
  <pre><code>    char chaine[12];
      cin.width(12);
      cin &gt;&gt; chaine;
  </code></pre>
  
  <p>But if I enter some text longuer than 12 characters at runtime, visual studio inform me that the stack is now corrupted.</p>
  
  <p>I understand that the problem is a buffer overflow. But I thought that the "width" method would protect against this.   </p>
  
  <p>Could someone explain to me what is the function of the width method if it does not protect against the buffer overflow? I searched online but i did not find anything.</p>
  
  <p>Thanks!</p>