So I've written this program for counting total number of words in a text file as well as the number of unique words in the file(i.e a word is unique only the first time it is encountered.) So far the total number of words using option t works perfectly but I am having trouble with the unique number of words function mainly the vector declared in it and where exactly to call it in main(). Help will be greatly appreciated, it's due in about 20 hrs. Thanks
You need to step back and think about what you're trying to do. You need to identify the unique words from all the words. So your unique words function is going to need to operate on a collection of all the words.
Currently, your getUniqueWords function takes a single string. One word. So it seems a logical impossibility to identify the number of unique words from all the words if you're only giving the function one single word.
As you read each word in, add it to a vector<string>, using push_back. When you're done reading words in, you will then have all the words in a single vector, ready for you to work on.
Alternatively, you could check to see if a word is already in the vector, and add it only if it isn't, and at the end simply count the number of words in the vector. There are many other ways to do this as well; the issue here is that you need to think in advance about how to do it, and then implement the solution you thought of. That's programming. Thinking and then implementing. Think of your solution first, and then code it.
As an aside, if you were doing this differently, you would add each word to a set<string> as you read them in. std::set removes duplicates for you, so when you had added all the words to the set, you would just ask it what size it was, and that would be the number of unique words.