hi, so i have been tasked with creating a dictionary application using c++ and im a beginner to coding. the task comprises of creating an application where 106,187 words are in a text file with their meaning and types and we need to search load all the words and be able to search them to find out their meanings and types(lie noun, adverb etc....) i have created a code, it seams to get all the lines correctly on to the 3 different variables but i cannot store them on any stl containers as i dont know how to. when i looked up online i found out about 2d arrays even thou i searched for it i could find any thing where they state that you can load data on to an array from a text file. please help..
my text file format is as below:
word
definition
type
If you can use struct's or classes and learn how to use <map>'s, none of which is too hard in your case, then that is the way to go rather than a 2D (3D would be better) synchronised/parallel arrays.
The reason <map>'s are better is searching and retrieving the data is much easier and quicker.
struct's and classes group/envelope/encapsulate each word/definition/type entry to make a single object.
Your prof may want you to make the data members private and add accessor methods. To me, they just get in the way for a simple program like this.
You can put these into a std::set, but std::set needs to know how to compare them. To do that, you add a less-than operator to the class. One entry is less than the other if the first's word is less than the second's:
With this operator defined, you can compare DictEntry objects with <. "Rhs" stands for "right hand side" and denotes the object on the right hand side of the operator. An example will help clarify this:
1 2 3 4
DictEntry a,b;
// Code to populate a and b
if (a < b) { // calls a::operator<(b)
std::cout << "a is less than b\n";
}
Now you can create a dictionary as a std::set of DictEntry