title: Reading in txt file c++
body: <p>I'm attempting to load a dictionary file into a binary search tree. I would like to load each node with a combination of letters until it forms a word, thus attaching a definition to that word. Example:</p>
  
  <pre><code>C:
  Ca:
  Cat: a mammal. Closely related to a Liger.
  </code></pre>
  
  <p>Currently, I'm attempting to load the sample file and I keep receiving my inFile.fail() conditions. Any help, advice, and/or code-review is greatly appreciated.</p>
  
  <p>Here are the two functions which I think may be causing my issue:</p>
  
  <pre><code>bool Dictionary::insertTrie(string word, string def)
  {
      Node* newNode = createTrie();
      string tempW;
      bool retVar;
      bool found = searchNode(root, word);
  
      if(found)
          retVar = false;
  
      while(!found){
          newNode-&gt;word = word;
          newNode-&gt;definition = def;
          insert(root, newNode);
          retVar = true;
      }
  
      /*while(!found){
          for(int i = 0; i &lt; word.length(); i++){ //loop to iterate through the string
              for(int j = 0; j &lt; ALPHABET_SIZE; j++){ //loop to iterate the nodes
                  tempW += word[i];
                  newNode-&gt;word = word;
                  newNode-&gt;definition = def;
                  newNode = newNode-&gt;next[j];
              }
  
              retVar = true;
          }*/
  
      return retVar;
  }
  
  
  bool Dictionary::loadDictionary(string fileName) 
  {
      fstream inFile;
      string file;
      string words;
      string defs;
      string tempW;
      bool retVar;
  
      inFile.open(fileName, ios::in); // opens
      cout &lt;&lt; "\nLoading Dictionary...\n";
  
      if(inFile.fail()){
          retVar = false;
          cout &lt;&lt; "ERROR: Dictionary file failed to load. Please try again.\n";
      }
      else{
          while(!inFile.eof()){ //loop reads in words and definitions until the end of file bit is received
              for(int i = 0; i &lt; words.length(); i++){
                  getline(inFile, words, ':');  //receives input of the words stopping at the ':' delimiter
                  tempW += words[i];
                  getline(inFile, defs, '\n'); //receives input of the defs stopping at the '\n' delimiter
                  insertTrie(tempW, defs); //inserts the words and the definition
              }
          }
          retVar = true;
      }
  
      inFile.close(); //closes the file
  
      return retVar;
  }
  </code></pre>