title: Reading "tokens" from a string line in C++ I/O
body: <p>I am wondering how I can do the following in C++ since I am only familiar with Java.</p>
  
  <p>I have a string which we will call line.
  string line = "hello how are you";</p>
  
  <p>In C++ I have retrieved that line from getLine(). I want to traverse through this line so I can count the number of words in this line. The result should be 4, in my example.</p>
  
  <p>In Java, I would have imported Scanner. Then do something like this:</p>
  
  <pre><code>//Other scanner called fileName over the file
  while(fileName.hasNextLine()) {
  line = fileName.nextLine();
  Scanner sc = new Scanner(line); 
  int count=0;
  while(sc.hasNext()){
      sc.next();
      count++;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I am only using <code>#include&lt;iostream&gt;, fstream and string.</code></p>