Ok, so now that we all understand the problem, it is quite easy to give an answer:
- read the file line by line
- split every line at common separators (spaces, dots, commas, colons, semi-colons, ...)
- store each word in a
std::vector<std::string>
When you have finished, you have a vector which contains every word in the file. Now you simply have to scan the vector and search for the word you want.
In order to split a string in words, you can use a function like this
1 2 3 4 5 6 7
|
void split(const std::string &s, char delim, std::vector<std::string> &elems) {
std::stringstream ss(s);
std::string item;
while (std::getline(ss, item, delim)) {
elems.push_back(item);
}
}
|
Of course you have to modify it a little bit to include more separators, but it shouldn't be too difficult.