How do these string functions wrok

I'm trying to find the number of times "the" occurs in the file. I'm using the .find function but when I don't use "!" in the if statement it gives me the number of other words in the function. However, when I use the "!" I get the correct number of "the". Also earlier today I was using the .compare function to see if two strings were the same (which they were) but without the "!" it gave me the result as if they were not the same...
Sorry if I explained poorly but could someone explain why this is?

1
2
3
          while (!file.eof()) {
		file >> word;
		if (!word.find("the")) { d++; }
closed account (48T7M4Gy)
If you have read in each word as a <string> then the test is if(word == "the")

If you have read in each word as a C-style string use strcmp() function
http://www.cplusplus.com/reference/cstring/strcmp/
Topic archived. No new replies allowed.