title: Iterating through a text file and assigning variables for each line
body: <p>having a difficult time finding a way to assign each line of the text file being read to a different variable, i commented above the variables displaying how a line from the text file displaying that variable would look. I want to know what way i can use a forloop to be able to iterate through the entire text file and store data to each of the variables I commented above based on the type of data it needs to store. The three sets of variables all have to be stored by species and in a way they can be manipulated. How can i split up a vector into a set of three variables? </p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  string getInputFileName()
  //retrieves the inputfile
  {
      string fileName;
      ifstream inputfile;
  
      //prompting user for filename to be opened
      cout &lt;&lt; "Enter the file name to be opened: ";
      cin &gt;&gt; fileName;
  
      //opening the file for input
      inputfile.open(fileName, ios::in);
  
      //checks to see if writing the input file failed
      if (inputfile.fail())
      {
          cout &lt;&lt; "Opening file..." &lt;&lt; fileName;
          cout &lt;&lt; "\n";
          cout &lt;&lt; "The " &lt;&lt; fileName &lt;&lt; "could not be opened! \n";
          cout &lt;&lt; "1. Check if file exists. \n";
          cout &lt;&lt; "2. Check file path. \n;";
  
      }
      else
      {
          cout &lt;&lt; "File: " &lt;&lt; fileName &lt;&lt; " was successfully opened!" &lt;&lt; endl;
          return fileName;
      }
  
  }
  string getOutputFileName()
  //retrieves the inputfile
  {
      string fileName;
      ofstream outputfile;
  
      //prompting user for filename to be opened
      cout &lt;&lt; "Enter the file name to be opened: ";
      cin &gt;&gt; fileName;
  
      //opening the file for input
      outputfile.open(fileName, ios::in);
  
      //checks to see if writing the input file failed
      if (outputfile.fail())
      {
          cout &lt;&lt; "Opening file..." &lt;&lt; fileName;
          cout &lt;&lt; "\n";
          cout &lt;&lt; "The " &lt;&lt; fileName &lt;&lt; "could not be opened! \n";
          cout &lt;&lt; "1. Check if file exists. \n";
          cout &lt;&lt; "2. Check file path. \n;";
  
      }
      else
      {
          cout &lt;&lt; "File: " &lt;&lt; fileName &lt;&lt; " was successfully opened!" &lt;&lt; endl;
          return fileName;
      }
  
  }
  
  
  int main()
  {
      //opens clasfication file
      ifstream inputFile(getInputFileName());
  
      //declaring year and numberOfSpecies
      int year, numberOfSpecies;
      string line;
  
      if (inputFile.is_open())
      {
          //year of file
          inputFile &gt;&gt; year;
          //echo for year
          cout &lt;&lt; year &lt;&lt; endl;
  
          //number of species of file
          inputFile &gt;&gt; numberOfSpecies;
          //echo for number of species
          cout &lt;&lt; numberOfSpecies &lt;&lt; endl;
  
          string line;
  
          //variables i need to assign line by line and be able to manipulate
          //region of species would look like this in text file: 84
          //nameOfspecies would like like this in the text file: Spotted Gecko
          //regionSightings would look like this in the text file: 84 95 30 25
  
  
  
          vector&lt;string&gt; linesOfData;
  
      for (int i = 0; (!inputFile.eof()) || (i &lt;= numberOfSpecies) ; i++)
      {
  
          getline(inputFile, line, '\n');
          linesOfData.push_back(line);
  
          //echo vector!
          cout &lt;&lt; linesOfData[i] &lt;&lt; "\n";
  
          }
          ofstream outputFile(getOutputFileName());
  
      }
  
      return 0;
  }
  </code></pre>