A simple C++ Trie for working with strings Here is a simple C++ 11 trie for insertion and membership testing:

#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;map&gt;
#include &lt;string.h&gt;

class TrieNode{
  //TrieNodes can also be used as tries
public:
  std::map&lt;char, TrieNode&gt; children;
  bool isLeaf;

  bool isContained(char * string){
    if (strlen(string)==0){
      return isLeaf;
     }

    char searchChar = *string; //the next char we are looking at

    if (children.find(searchChar) == children.end()){
      return false;
    }

    /*search for everything but the first char from the string in the trie
      for the first char*/
    return (children[searchChar].isContained(1+string));
  }

  void insertString(char * string){
    if (strlen(string) == 0){
      //If an empty string has been parsed then this node is the end of a string
      isLeaf = true;
      return;
    }

    char searchChar = *string;

    if (children.find(searchChar) == children.end()){
      //Create a new trie for the first character of our string
      TrieNode newNode;
      children[searchChar] = newNode;
    }

    children[searchChar].insertString(string+1);
  }
};

int main(){
  //Sample main function
  TrieNode myTrie;
  printf("hello in trie = %d\n",myTrie.isContained((char *) "hello"));
  myTrie.insertString((char *) "hello");
  printf("hello in trie = %d\n",myTrie.isContained((char *) "hello"));
  return 0;
}


I am relatively new to C++ (I have been muddling around with it for maybe a year now) so am wondering whether I may have either accidentally given my code nasal demons and/or accidentally wasted a lot of memory.
A couple of thoughts. 


Maybe a distinction between Trie and TrieNode might make sense. So TrieNode can be defined as an inner struct within an outer class Trie.
There is no compelling reason to use a char* string representation rather than using string.
unordered_map would do just as well as a map, and possibly be faster.
You can consider iterating using a while loop instead of recursion in isContained.