title: c++ input words from text file in binary search tree
body: <p>I am trying to write a program that will read words from a text file and insert it into a binary tree.  If the word is more than 10 characters, then the word will get cut at 10 characters.  I feel like I am really close to getting this but when I run the program, it crashes and I receive no errors.  I tested the binary search tree with just integers and it works.  I also tested reading the words from a text file without putting it in a binary tree and that also works.  But when I fuse the two together.. That's where I am having issues.  Also, the end of the text file is denoted by "#".  Just so the break; makes sense.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  struct Node{
      string data;
      Node* left;
      Node* right;
  };
  
  Node* GetNewNode(string data){
      Node* newNode = new Node();
      newNode-&gt;data=data;
      newNode-&gt;left = newNode-&gt;right = NULL;
  }
  
  Node* Insert(Node* rootPtr,string data){
      if(rootPtr == NULL){
          rootPtr = GetNewNode(data);
          return rootPtr;
      }
      else if(data&lt;= rootPtr-&gt;data){
          rootPtr-&gt;left = Insert(rootPtr-&gt;left,data);
      }
      else {
          rootPtr-&gt;right = Insert(rootPtr-&gt;right,data);
      }
      return rootPtr;
  }
  
  int main() {
  string word;
  ifstream inFile;
  Node* rootPtr = NULL; // Pointer to the root node
  
  inFile.open("example.txt");
  if (!inFile) {
  cout &lt;&lt; "Unable to open text file";
  }
  
  while (inFile &gt;&gt; word) {
      rootPtr = Insert(rootPtr,word.substr(0,10));
      if (word == "#")
          break;
  }
  
  inFile.close();
  }
  </code></pre>
  
  <p>Thanks for any input!</p>