title: Segmentation Fault - Invalid read of size 8
body: <p>For some reason the following C++ code results in a segmentation fault:</p>
  
  <pre><code>#include &lt;sstream&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  string charToString(char c)
  {
      stringstream ss;
      string s;
      ss &lt;&lt; c;
      ss &gt;&gt; s;
  
      return s;
  }
  
  int main()
  {
      vector&lt;string&gt; stringTable;
  
      for(int c = 0; c &lt; 256; ++c){
          string s = charToString(c);
          stringTable[c] = s;
      }
  }
  </code></pre>
  
  <p>Valgrind reports the error <code>Invalid read of size 8</code> on the line</p>
  
  <pre><code>stringTable[c] = s;
  </code></pre>
  
  <p>But I can't see what's wrong with this line. So what is wrong with this code?</p>