finding whether the word ispreviously present in file data.txt or not

finding whether the word is previously present in file data.txt or not?


what will be function for it?
Read all of data.txt into a std::string. Use find() to check if "the word" is in it.
http://www.cplusplus.com/reference/string/string/find/
If you are looking for a particular word, read each word one-by-one from file and compare them with your particular word as you do so. Stop when either you match words or reach the end of file.

If you are determining if ANY words in the file are the same then there are various options. You could push_back them all into a vector<string>, then use the algorithms sort and adjacent_find. Alternatively, you could read the words one-by-one and try putting them in a std::set. This won't accept duplicates.

In either case, you may want to run any words that you input through a filter, so that you can strip out punctuation, make consistent case etc.
Topic archived. No new replies allowed.