title: Reading file into linked list C++ with node structure in a class
body: <p>I'm trying to read a text file containing the letters "farming" into a linked list of nodes. I've made a class named NumberList that has the structure for the nodes. Here's the header.</p>
  
  <pre><code>#ifndef NUMBERLIST
  #define NUMBERLIST
  #include &lt;iostream&gt;
  
  using namespace std;
  
  class NumberList
  {
  protected:
  //declare a class for the list node
  //constructor to initialize nodes of list
  struct ListNode
  {
      char value;
      ListNode *next;
  
      // Constructor 
      ListNode(char value1, ListNode *next1 = NULL)
      {
          value = value1;
          next = next1;
      }
  };
  
  ListNode *head;  //pointer to head of the list
  
  public:
  NumberList() { head = NULL; }  //constructor 
  ~NumberList();      //destructor
  void displayList() const;  //print out list
  void reverse();
  
  };
  #endif
  </code></pre>
  
  <p>Where I'm running into a problem is trying to read the text file into a linked list in main().</p>
  
  <p>Here's what I have in main:</p>
  
  <pre><code>#include "Numberlist.h"
  #include "ReliableNumberList.h"
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  
  
  using namespace std;
  
  int main()
  {
  
  ListNode *letterList = nullptr;  //create a linked list
  char letter;
                      //This is where I read the file into the list
  //open the file
  ifstream letterFile("linkedText.txt");
  if (!letterFile)
  {
      cout &lt;&lt; "Error in opening the file of letters.";
      exit(1);
  }
  //read the file into a linked list
  while (letterFile &gt;&gt; letter)
  {
      //create a node to hold this letter
      letterList = new ListNode(letter, letterList);
      //missing a move to the next node?
  }
  return 0;
  }
  </code></pre>
  
  <p>This read file sample came from my text book but the structure its reading into was not located in a separate class. For the life of me I cannot figure out how I reference ListNode struct in the NumberList class. Visual Studio is stating that ListNode and letterList are undefined. I know its because I'm not referencing them properly from the NumberList class. </p>
  
  <p>Any help would be greatly appreciated.</p>