I have this dictionary project that's making my head spin. Am trying to create a dictionary that stores the word and meaning of the word in a text file. Then a user can either searching the meaning of a word or search by alphabet.
I had an idea which is, i wanted to use a function that searches for a specific string in a text file but i dont know how. I hope this is all not too confusing.
please help.
Thanks in advance.
kazek 0 Newbie Poster
Recommended Answers
Jump to Postsearching a file for a specific string is fairly straight forward. Open the file, read each line and search the lines for desired string. use std::ifstream object for the file, getline() to read each line into a std::string object, the use the string's find() method to see if it contains …
Jump to Post>>What's the syntax for the string's find method
It only has one parameter -- the string you want to look for. It returns either string::npos when the string is not found or the index where it starts.
Jump to Postin your example read the whole line then extract just the first word and compare it. To extract the first word look for space and use substring method.
std::string line = "semantic relating to the meaning of words"; std::string::size_type spot = line.find(' '); // look for a …
Jump to Postline 53 is missing the parameter to getmeaning().
Since this is a c++ program you should use references instead of C-style pointers. Makes the program less prone to errors
getmeaning(string& str); .. void Dictionary::getmeaning(string& p) { }
..
All 15 Replies
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
kazek 0 Newbie Poster
Hamrick 150 Posting Whiz

iamthwee
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
kazek 0 Newbie Poster
kazek 0 Newbie Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
kazek 0 Newbie Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
kazek 0 Newbie Poster
Bench 212 Posting Pro

iamthwee
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
kazek 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.