title: Trying to read from a file and skip punctuation in C++, tips?
body: <p>I'm trying to read from a file, and make a vector of all the words from the file. What I tried to do below is have the user input the filename, and then have the code open the file, and skip characters if they aren't alphanumeric, then input that to a file.</p>
  
  <p>Right now it just closes immediately when I input the filename. Any idea what I could be 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;
  using namespace std;
  
  int main() 
  {
  
  string line; //for storing words
  vector&lt;string&gt; words; //unspecified size vector
  string whichbook;
  cout &lt;&lt; "Welcome to the book analysis program. Please input the filename of the book you would like to analyze: ";
  cin &gt;&gt; whichbook;
  cout &lt;&lt; endl;
  
  ifstream bookread;
  //could be issue
  //ofstream bookoutput("results.txt"); 
  
  bookread.open(whichbook.c_str());
  //assert(!bookread.fail());
  
  if(bookread.is_open()){
      while(bookread.good()){
          getline(bookread, line);
          cout &lt;&lt; line;
          while(isalnum(bookread)){
              words.push_back(bookread);
          }
      }
  }
  cout &lt;&lt; words[];
  }
  </code></pre>