title: C++ - Parsing file iterating twice over last line
body: <p>I currently have a text file that looks like the following:</p>
  
  <p>California 22 23</p>
  
  <p>Washington 43 11</p>
  
  <p>Oklahoma 98 23</p>
  
  <p>The format of each line is string, double, double. Each is separated by a single space. I have the following method to read the file, however it seems to iterate over the last line of the text file twice, why is this? (i.e. it creates two City objects with the name 'Oklahoma')</p>
  
  <pre><code>void openFile() {
  
      string line, name;
      double latitude, longitude;
  
      ifstream thefile("text.txt");
      if (thefile.is_open()) {
          while (getline(thefile, line)) {
              std::stringstream n(line);
              n &gt;&gt; name &gt;&gt; latitude &gt;&gt; longitude;
              City newCity(name, latitude, longitude);
              addNode(newCity);
          }
          thefile.close();
      }
  }
  </code></pre>