title: Read input file word by word
body: <p>I will first off say that yes, this is a homework assignment, but my teacher is really not too clear on how to do things.</p>
  
  <p>I'm asked to, in c++, Write a function that will pass words from a file one at a time.  The function will calculate the word length and then print out TO SCREEN the word and its length on its own line.</p>
  
  <p>The main will open your input file, read it word by word in a loop and then pass the word into your function for it to be printed.</p>
  
  <p>I know how to open a file using fstream and all that, read it word by word, but not in a loop or a function by the void readfile () one. My problem here is putting everything together.</p>
  
  <p>This is my program to open a file, get the length and display it in a parallel array</p>
  
  <pre><code>//declare parallel arrays
  
  string words [MAXSIZE];
  
  //open files
  outputFile.open("output.txt");
  inputFile.open ("/Users/cathiedeane/Documents/CIS 22A/Lab 4/Lab 4 Part 2/lab4.txt");
  
  
  //inputvalidation
  
  while (!inputFile.eof())
  {
      for(int i = 0; i &lt; MAXSIZE; ++i)
      {
  
          outputFile &lt;&lt; words[i] &lt;&lt; " " &lt;&lt; endl;
          inputFile &gt;&gt; words[i];
  
      }
      inputFile.close();
  
  }
  for (int i= 0; i &lt;= MAXSIZE; i++)
  
  {   cout &lt;&lt; words[i] &lt;&lt; ":" &lt;&lt; words[i].size()&lt;&lt; endl;
      outputFile &lt;&lt; endl;
  }
  
  //close outputfile
  outputFile.close();
  return 0;
  }
  </code></pre>