I am trying to write a program that splits a poem into separate words, loads them into an array(without making duplicate words), counts how many times a word is used in the poem and on what lines, and prints out a statements reading off the 3 things. I have an array that is full of the words but i cannot figure out how to search in to see if a word is used already so if so it is skipped. And i cannot figure out how to write an array to put all the times a word is used in the poem.
You can make a struct that will take an string a count of it's occurences and a vector to store the lines in wich it occurs , then load them into a vector
1 2 3 4 5 6 7 8 9 10 11 12 13 14
struct oneword
{
string word=""; //will store the read word
int count=0; // store the number of occurences
vector<int> lines; /// stores the lines in which the word occurs
};
/// each word read from the file is pluged into a object then into a vector, if it occurs again you'll just
/// increment its count
vector<oneword> analysis; /// vector will hold oneword objects and iit's details
infile>> aline;
//check if aline is present in the vectors , if so increment it's count else create a oneword object then set
// it's variable word to aline and increment it count , add the lune of occurence then add it to the vector