Checking if word exists in a text file c++

c++, file, text

Solution

char aWord[50];
while (file.good()) {
    file>>aWord;
    if (file.good() && strcmp(aWord, wordToFind) == 0) {
        //found word
    }
}

You need to read words with the input operator.

Problem

I need to check if a word exists in a dictionary text file, I think I could use strcmp, but I don't actually know how to get a line of text from the document. Here's my current code I'm stuck on. ``` #include "includes.h" #include <string> #include <fstream> using namespace std; bool CheckWord(char* str) { ifstream file("dictionary.txt"); while (getline(file,s)) { if (false /* missing code */) { return true; } } return false; } ```

Original source