Hi I am writing a program that counts the number of times each word occurs in a file. Then it prints a list of words with counts between 800 and 1000, sorted in the order of count. I am stuck on keeping a counter to see if the first word matches the next until a new word appears. In the main I am trying to open the file, read each word by word and call sort in the while loop to sort the vector. Then, in the for loop go through all the words and if the first word equals the second count++. I don't think that is how you keep a counter.
struct words
{
string word;
int occurrences;
};
vector<words*> Vstruct;
read the first word into a new struct and set occurrences to 1, push into vector.
read the second word, if it is in the vector update that words occurrences else, new struct, push.
repeat.
While (not end of file)
{
read a word into a string variable.
-start an inner loop to iterate through the vector and check if the word is in there.
if the word is not in the list. (it will not be for the first word)
{
create new struct and set occurrences to 1, push into vector.