title: Reading data in from file and inserting into Linked List C++
body: <p>For this program, I have to read in a list of names from a txt file and create a new node for each name, then insert the node into a linked list and keep it sorted as new names are read in. I am having difficulty properly reading in the file line by line, and creating a new node and putting the data in. I am very new to linked lists, but the logic seems sound in my insert function, and I think my errors are caused by my syntax. 
  Here is my main so far:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include "SortedLinkList.h"
  using namespace std;
  
  int main()
  {    
     SortedLinkList&lt;string&gt; sll;    //create sortedlinklist object
     SortedLinkList&lt;string&gt; sll2;
  
     ifstream infile("List1.txt");
     if(infile.fail()) {
        cout &lt;&lt; "the input file could not be opened" &lt;&lt; endl;
        exit(0);
     }
     else {
        cout &lt;&lt; "Opening file 1" &lt;&lt; endl;
        string s;
        while (infile &gt;&gt; s)
        {
          infile &gt;&gt; sll;         
          sll.insert(s); //attempting to create new node and use data read 
                           from file
        }
     }
  }
  </code></pre>
  
  <p>Here is my insert function. Which is in "SortedLinkList.h"
  The class is templated, and a Node.h class has already been provided,
  which has the getData() and getNext() function already. The variables current,head,previous, and count have all been declared. The "node.h" file is #included in the "SortedLinkList.h".</p>
  
  <pre><code>template &lt;class T&gt;
  void SortedLinkList&lt;T&gt;::insert(const T &amp; value)
  {
      cout &lt;&lt; "insert data" &lt;&lt; endl;
      //allocate a node with new
      Node&lt;T&gt; *newNode, *current, *previous;
      newNode = new Node&lt;T&gt;(value);
      current = head;
      previous = 0;
      while(current != NULL)
      if(head == 0)
      {
          head = newNode;
      }
      else
      {
          SortedLinkList* current = head;
          SortedLinkList* previous = 0;
  
          //traverse list to find ins. location
          while(current != 0)
          {
              if(current-&gt;getData() &gt;= newNode-&gt;getData())
              {
                  break;
              }
              else
              {
                  previous = current;
                  current = current-&gt;getNext();
              }
          }
          //insert at head
          if(current == head)
          {
              newNode-&gt;getNext() = head;
              head = newNode;
          }
          //insert after head
          else
          {
              newNode-&gt;getNext() = current;
              previous-&gt;getNext() = newNode;
          }
      }
      count++;
  }
  </code></pre>