File: main.cpp

package info (click to toggle)
libclaw 1.7.4-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,080 kB
  • sloc: cpp: 13,287; sh: 227; makefile: 8
file content (58 lines) | stat: -rw-r--r-- 1,644 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "claw/trie.hpp"
#include <iostream>
#include <fstream>

int main()
{
  const std::string filename = "words.txt";
  std::ifstream text(filename.c_str());

  if (!text)
    std::cerr << "Can't open file '" << filename << "'" << std::endl;
  else
    {
      std::string word;
      claw::trie<char> dictionary;

      while ( text >> word )
        dictionary.insert(word.begin(), word.end());

      text.close();

      std::cout << dictionary.size() << " words." << std::endl;

      if (dictionary.empty())
        std::cout << "Dictionary is empty but shouldn't !!\n" << std::endl;
      else 
        std::cout << "Dictionary is not empty.\n" << std::endl;

      claw::trie<char> dictionary_copy(dictionary);

      dictionary.clear();

      if (dictionary.empty())
        std::cout << "Dictionary is empty.\n" << std::endl;
      else 
        std::cout << "Dictionary is not empty but should !\n" << std::endl;

      std::cout << "Dictionary copy" << std::endl;

      std::cout << dictionary_copy.size() << " words.\n" << std::endl;
      if (dictionary_copy.empty())
        std::cout << "Dictionary is empty but shouldn't !!" << std::endl;
      else 
        std::cout << "Dictionary is not empty" << std::endl;

      std::cout << "Type a word to get how many times it's in the text, ";
      std:: cout << "quit' to quit" << std::endl;
      do
        {
          std::cin >> word;
          std::cout << word << " is present " 
                    << dictionary_copy.count(word.begin(), word.end()) 
                    << " times." << std::endl;
        }
      while (word != "quit");
    }
  return 0;
} // main()