title: Vector subscript out of range error, C++
body: <p>When I try to run this program I get an error that halts the program and says, "Vector subscript out of range"</p>
  
  <p>Any idea what I'm doing wrong?</p>
  
  <pre><code>#include &lt;vector&gt;
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  #include &lt;fstream&gt;
  #include &lt;sstream&gt;
  using namespace std;
  
  //(int argc, char* argv[]
  int main()
  {
      fstream bookread("test.txt");
      vector&lt;string&gt; words;
  
      bookread.open("test.txt");
      if(bookread.is_open()){
          cout &lt;&lt; "opening textfile";
          while(bookread.good()){
              string input;
              //getline(bookread, input);
              bookread&gt;&gt;input;
              //string cleanedWord=preprocess(input);         
              //char first=cleanedWord[0];
              //if(first&lt;=*/
              //cout &lt;&lt; "getting words";
              //getWords(words, input);
          }
      }
      cout &lt;&lt; "all done";
  
      words[0];
  
  getchar();
  }
  </code></pre>