title: Reading in a .txt file word by word to a struct in C++
body: <p>I am having some trouble with my lab assignment for my CMPT class...
  I am trying to read a text file that has two words and a string of numbers per line, and the file can be as long as anyone makes it.</p>
  
  <p>An example is</p>
  
  <pre><code>Xiao Wang 135798642
  Lucie Chan 122344566
  Rich Morlan 123456789
  Amir Khan 975312468
  Pierre Guertin 533665789
  Marie Tye 987654321
  </code></pre>
  
  <p>I have to make each line a separate "student", so I was thinking of using struct to do so, but I don't know how to do that as I need the first, last, and ID number to be separate.</p>
  
  <pre><code>struct Student{
      string firstName;
      string secondName;
      string idNumber;
  };
  </code></pre>
  
  <p>All of the tries done to read in each word separately have failed (ended up reading the whole line instead) and I am getting mildly frustrated.</p>
  
  <p>With the help from @Sylence I have managed to read in each line separately. I am still confused with how to split the lines by the whitespace though. Is there a split function in ifstream?
  Sylence, is 'parts' going to be an array? I saw you had indexes in []'s.
  What exactly does the <code>students.add( stud )</code> do?
  My code so far is:</p>
  
  <pre><code>int getFileInfo()
  {
      Student stdnt;
      ifstream stdntFile;
      string fileName;
      char buffer[256];
      cout&lt;&lt;"Please enter the filename of the file";
      cin&gt;&gt;filename;
      stdntFile.open(fileName.c_str());
      while(!stdFile.eof())
      {
          stdFile.getLine(buffer,100);
      }
      return 0;
  }
  </code></pre>
  
  <p>This is my modified and final version of getFileInfo(), thank you Shahbaz, for the easy and quick way to read in the data.</p>
  
  <pre><code>void getFileInfo()
  {
      int failed=0;
      ifstream fin;
      string fileName;
      vector&lt;Student&gt; students; // A place to store the list of students
  
  Student s;                  // A place to store data of one student
  cout&lt;&lt;"Please enter the filename of the student grades (ex. filename_1.txt)."&lt;&lt;endl;
  do{
      if(failed&gt;=1)
          cout&lt;&lt;"Please enter a correct filename."&lt;&lt;endl;
      cin&gt;&gt;fileName;
  fin.open(fileName.c_str());// Open the file
  failed++;
  }while(!fin.good());
  while (fin &gt;&gt; s.firstName &gt;&gt; s.lastName &gt;&gt; s.stdNumber)
      students.push_back(s);
  fin.close();
  cout&lt;&lt;students.max_size()&lt;&lt;endl&lt;&lt; students.size()&lt;&lt;endl&lt;&lt;students.capacity()&lt;&lt;endl;
  
  
  return;
  }
  </code></pre>
  
  <p>What I am confused about now is how to access the data that was inputted! I know it was put into a vector, but How to I go about accessing the individual spaces in the vector, and how exactly is the inputted data stored in the vector? If I try to cout a spot of the vector, I get an error because Visual Studio doesn't know what to output I guess..</p>