title: Reading text file into a linked list C++
body: <p>I have been trying to read a text file into a linked list. The only problem I face is that it wont read all the entries.</p>
  <p>My class for Student:</p>
  <pre><code>class Student // Student class which hold student data
  {
  private:
      char Name[15];
      char Roll_no[8];
      int Serial_no, FSC_marks, Entry_test_marks;
  public:
      void Print() // Print student data
      {
          cout &lt;&lt; &quot;\n&quot; &lt;&lt; Serial_no &lt;&lt; &quot;\t&quot;&lt;&lt; Roll_no &lt;&lt; &quot; &quot; &lt;&lt; Name &lt;&lt; &quot;\t&quot; &lt;&lt;  FSC_marks &lt;&lt; &quot;\t\t&quot; &lt;&lt; Entry_test_marks &lt;&lt; endl;
      }
  
      void Read(fstream &amp;infile)
      {
          infile &gt;&gt; Serial_no;
          infile &gt;&gt; Roll_no ;
          infile.get(Name,15);
          infile &gt;&gt; FSC_marks &gt;&gt; Entry_test_marks; 
      }
  }
  </code></pre>
  <p>Class for Linked List</p>
  <pre><code>class LinkList // Linked List 
  {
      struct Node // structure for Node containing Object of Student class
      {
          Student info;
          Node* link;
      };
      Node* head;
      
  public:
      
      Linklist() // default constructor
      {
          head = NULL;
      }
  };
  </code></pre>
  <p>Here's the printing fucntion:</p>
  <pre><code>void LinkList::print() // Prints List of Students
  {
      Node* temp = head;
          
      if(temp != NULL)
      {
          while(temp != NULL)
          {
              temp-&gt;info.Print();
              temp = temp-&gt;link;
          }
          
          cout&lt;&lt;endl;
      }
  }
  </code></pre>
  <p>Here's the Reading function:</p>
  <pre><code>void LinkList::Readfromfile()
  {
      fstream File;
      File.open(&quot;Lab_15.txt&quot; , ios::in);
      File.seekg(40);
      
      while(File)
      {
          Node* newnode = new Node();
          newnode-&gt;info.Read(File);
          newnode-&gt;link = NULL;
          
          if(head == NULL)
          {
              head = newnode;
          }
              
          else
          {
              Node* temp = head;
              while(temp-&gt;link != NULL)
              {
                  temp = temp-&gt;link;
              }
                  
          temp-&gt;link = newnode;
          }
      }
  }
  </code></pre>
  <p>And here's how the text file looks like:</p>
  <pre><code>Serial_No   Roll_No Name    F.Sc    Entry_Test
  1   19I-0777    Jame#s moriarty777  70
  2   19I-0789    Sherlock    734 80
  3   19I-0860    Holmes      843 88
  4   19I-0884    Dave Bautista   732 54
  6   20I-1003    Barry Allen#    712 32
  7   20I-1004    Clark kent  632 15
  8   20I-1015    Adam        658 67
  9   20I-1034    Ahmad hussain   734 55
  10  20I-1041    Bill ga#tes 811 98
  11  20I-1054    Trump       888 45
  13  20I-1057    Donald duck 576 67
  14  20I-1903    Faiza#n Shahid  789 34
  15  20I-1904    Umair Shahid    567 55
  16  20I-1909    Abdullah    123 67
  17  20I-1915    Ali         300 45
  </code></pre>
  <p>In the original text file i have about 20 entries, but my code only reads about 13. What am I doing wrong here?</p>