How would one go about doing this? I am very fond with Windows I/O, but not so much with this subject. I am decent with fstream, probably not as skilled at it as I should be, but I assume <fstream> would be a better choice, since it isn't locked to Windows.
Anyway, say I have a .txt file like this:
Bill is a cow.
Bill likes meat.
Bob is a pig.
Bob and Bill are friends.
And I want to count the number of times "Bill" is written. How would I do that?
istream's >> operator extracts things one word at a time (seperated by whitespace). So just keep extracting words with >> until you reach the end of the file. And count the number of times the word you extracted was "Bill"
Note that if punctuation is an issue, you'll have to manually remove the punctuation from the extracted word. IE: "Bill." would not match "Bill" because of the period.
Use a do while loop to iterate through the file and use the std::string.compare() or std::string.find() member functions to evaluate the portion of the file you read in. If you find one matching "Bill" then increment some counter variable. So something like:
Wow that makes a lot of sense. I haven't tried it yet, since I am exhausted and about to pass out on my desk and don't feel like opening up VSC++, I will probably test that code in the morning or after school tomorrow. Thanks for the answers, guys! I be here tomorrow!