title: Why is copying a linked list to a vector giving a segmentation fault?
body: <pre><code>int main() {
      LinkedList list;
      for (int i = 1; i &lt;= 5; i++)
          list.appendFront(i);
  
      vector&lt;int&gt; list_copy;
      Node *temp = list.head;
      int i = 0;
      while (temp-&gt;next)
      {
          list_copy[i] = temp-&gt;info; //segmentation fault at this line
          temp = temp-&gt;next;
          i++;
      }
  
      for (auto i : list_copy)
          cout &lt;&lt; i;
  }
  </code></pre>
  
  <p>Please note that I am using my implementation of Linked List and it works fine.</p>