Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
How To Search For A Word And Show The Text Under it In C++ ?
I'm Making a dictionary software in C++ .
I Have a plain text file containing all the words and their definitions. I Know how to open the file using ifstream or fstream, but the problem is i don't know how to search for a word and show it's definition written just below it.
It has the word written in All U3A ".
Can You tell me some code that can be used for getting the input from the user, the word that#39;s definition (if found).
Please Help!
Example of how the file looks like -
AAM
Aam, n. Etym: [D. aam, fr. LL. ama; cf. L. hama a water bucket, Gr.
Defn: A Dutch and German measure of liquids, varying in different
cities, being at Amsterdam about 41 wine gallons, at Antwerp 36½, at
Hamburg 38¼. [Written also Aum and Awm.]
AARD-VARK
Aard"-vark`, n. Etym: [D., earth-pig.] (Zoöl.)
Defn: An edentate mammal, of the genus Orycteropus, somewhat
resembling a pig, common in some parts of Southern Africa. It burrows
in the ground, and feeds entirely on ants, which it catches with its
long, slimy tongue.
AARD-WOLF
Aard"-wolf`, n. Etym: [D, earth-wolf] (Zoöl.)
Defn: A carnivorous quadruped (Proteles Lalandii), of South Africa,
resembling the fox and hyena. See Proteles.
AARONIC; AARONICAL
Aa*ron"ic, Aa*ron"ic*al, a.
Defn: Pertaining to Aaron, the first high priest of the Jews.
AARON'S ROD
Aar"on's rod`. Etym: [See Exodus vii. 9 and Numbers xvii. 8]
1. (Arch.)
Defn: A rod with one serpent twined around it, thus differing from
the caduceus of Mercury, which has two.
2. (Bot.)
Defn: A plant with a tall flowering stem; esp. the great mullein, or
hag-taper, and the golden-rod.
AB-
Ab-. Etym: [Latin prep., etymologically the same as E. of, off. See
Of.]
Defn: A prefix in many words of Latin origin. It signifies from, away
, separating, or departure, as in abduct, abstract, abscond. See A-
(6).
AB
Ab, n. Etym: [Of Syriac origin.]
Defn: The fifth month of the Jewish year according to the
ecclesiastical reckoning, the eleventh by the civil computation,
coinciding nearly with August. W. Smith.
ABACA
Ab"a*ca, n. Etym: [The native name.]
Defn: The Manila-hemp plant (Musa textilis); also, its fiber. See
Manila hemp under Manila.
2 Answers
- AmitLv 58 years agoFavorite Answer
I would not write the code for you, but I will give you some pointers.
1. First you need to parse that file. For parsing you will have to scan the file line by line, separate out the words, by using things like strtok. The result of the parsing should be pairs of [word, meaning].
2. Then you need to store the [word, meaning] pairs in a data structure that allows for efficient lookup. C++ map data structure can do that.There are more efficient data structures available as well, such as hash tables. If you start going that route then you would have to do whole algorithmic analysis - O(n) complexity, memory usage etc. I recommend stick with maps - it works most of the time for lookups.
If the lookups are one off, i.e. program fires and then answers only a few queries, then simply search in the file all the time, without putting it into a data structure. Simply use the string find functions on the file content that you read. That would give you the position of where it found the string; read the next few lines to print the meaning. You will still need parsing code - you have to figure out where a word starts, where the meaning starts, and where the meaning ends.
- Anonymous5 years ago
Clear History