title: Reading and Storing data from text file C++
body: <p>I have a question similar to the one posted here:</p>
  
  <p><a href="https://stackoverflow.com/questions/3946558/c-read-from-text-file-and-separate-into-variable#">C++: Read from text file and separate into variable</a></p>
  
  <p>The difference is that the original post had the file.txt in the following format:</p>
  
  <ul>
  <li>name int int int </li>
  <li>name int int int</li>
  </ul>
  
  <p>My file has the following format:</p>
  
  <ul>
  <li><p>fname lname</p></li>
  <li><p>int int int</p></li>
  <li><p>fname lname</p></li>
  <li><p>int int int</p></li>
  </ul>
  
  <p>I am trying to read the name in (first and last) and store it to a single variable and each int into its own separate variable (for future calculations).</p>
  
  <p>I have tried using something similar to the answer, but the newlines are messing up my variables.</p>
  
  <p>As an added bonus, there are random blank lines in my file.</p>
  
  <p>Here is the code I have so far</p>
  
  <pre><code>if (myfile.is_open())
  {    
      while (getline(myfile, line))
      {
          istringstream iss(line);
  
          string fname;
  
          string lname;
  
          if (line != "")
          {
              iss &gt;&gt; fname &gt;&gt; lname &gt;&gt; x &gt;&gt; y &gt;&gt; z &gt;&gt; a &gt;&gt; b &gt;&gt; c;
              cout &lt;&lt; "name: " &lt;&lt; fname &lt;&lt; endl;
              //iss &gt;&gt; x &gt;&gt; y &gt;&gt; z &gt;&gt; a &gt;&gt; b &gt;&gt; c;
              cout &lt;&lt; "x: " &lt;&lt; x &lt;&lt; "y: " &lt;&lt; y &lt;&lt; endl;
  
          }
          else cout &lt;&lt; "";
      }
  }
  </code></pre>