tags:

views:

87

answers:

1

Hi,

I am trying to write a C++ function that matches whether a string is present in a dictionary . It can be a partial string or a complete string. SO I read each and every line into a trie

           trie< std::string, int > dict;
           dict.insert(make_pair(line,i++));
            // when i search for a string it always returns invalid.
           if(dict.find("AA")!=dict.end())
               cout<<valid<<endl;
           else
               cout<<invalid<<endl;

Can some one please help me with this. I added code for reading words in dictionary.

if(myfile.is_open())
{

      int i=0;
  string line;

      cout<<dict.size()<<endl;
      while(!myfile.eof())
  {
      getline(myfile,line);
      dict.insert(make_pair(line,i++));



  }
 } 
A: 

If you're using this trie, this sample code indicates you need more template parameters in your declaration to tell it how to split up the keys so it can do the trie indexing and especially prefix searches:

trie< std::string, int, string_trie_e_access_traits<>, pat_trie_tag, trie_prefix_search_node_update> dict;

Also note the use of prefix_range in the search function in the linked sample code.

Walter Mundt