I have to provide a definition for a word using terminal commands, the word is in a text file and I have to find the correct word then give part of speech and definition. Some of the words have multiple phrases and are separated like "learn;study;read". so im using string streams to allow me to getline and use a delimiter to separate from the phrases. but it's not working.
int main(int argc, char **argv){
std::ifstream in_file("/srv/datasets/wordnet.sorted.txt");
if(in_file.fail()){
std::cout << "file could not be opened" << std::endl;
return 0;
}
std::string word;
std::string part_of_speech;
std::string definition;
bool correct_word = false;
std::string user_input = argv[0]; //what word to look up
for(std::string dictionary_line; std::getline(in_file, dictionary_line);){ //used to go through each line of the file
std::istringstream term (dictionary_line); //allows us to use the line as input
std::string phrases; //the word and phrasing of the word of the line
std::getline(term, phrases, '\t'); //gets the word and phrasing
std::istringstream find_phrase (phrases); //used to parse through the phrasing just in case it has multiple phrases
for(std::string line; std::getline(find_phrase, line, ';');){ //used to parse through multiple phrases seperated by> if(line == user_input){ //checks if the current phrase matches the user input
correct_word = true; //sets this to true for an if statement after this loop
std::cout << line;
break; //used to break out of this loop if we found the word. If not it will loop through again.
}//if the word is not in this line then it will not set correct_word to true and then it will loop to the next li> }
if (correct_word == true) { //when we find the correct word it will use dictionary_line which will be on the correc> std::istringstream line_parsing(dictionary_line);
std::getline(line_parsing, word, '\t');
std::cout << word << std::endl;
std::getline(line_parsing, part_of_speech, '\t');
std::cout << part_of_speech << std::endl;
std::getline(line_parsing, definition, '\t');
std::cout << definition << std::endl;
break;// this should break the outside loop and end the program
}