title: Increment index of vector with some user input vector[x]++
body: <p>I would like to state that I'm new to programming and really having a hard time to figure out the pattern where a user inputs few elements and pushing all those elements to a vector and increment it. </p>
  
  <pre><code>int n, count = 0;
  std::cin &gt;&gt; n;
  std::vector&lt;int&gt; vec(n);
  for (size_t i = 0; i &lt; n; i++)
  {
      int x;
      std::cin &gt;&gt; x;
      vec[x]++;
      std::cout &lt;&lt; vec[i] &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>for a sample input of 6<code>(n)</code> elements : <strong>1 2 2 3 1 2</strong></p>
  
  <p>The vector contains : <strong>0 1 2 1 0 0</strong> </p>
  
  <p>It would be of a great help if anyone sheds some light to it.</p>
  
  <p>Thanks in advance</p>