I am trying to write a program where i let the user input a string, and compare it to see which words where used the most least and the mode, i having trouble with the vector words, when i push_back the input it evaluates it as One, how do i get the string to be evaluated by the words, and also just to test trying to output the words in the string in order from lowest to highest
The rabbit rabbit had more than one two rabbit The
Or type a word, hit enter, type another word hit enter etc.
What you have so far looks like the input is supposed to have an array of words? After further reading your question I think what you are asking is why are the multiple words I'm typing in evaluated as one word, instead of multiple.
Once you get your resp from the user, you can then split that string based on some delimeter, like space or commas pushing back each individual word.
Have the user input the line with words seperated with commas, like this: you, me, you, them, i , you, they, few
You would then iterate through the string using a loop, like this.
1 2 3 4 5 6 7 8 9 10
unsignedint count(0);
string in;
while (count < resp.length()){
in = in + resp[count];
if (resp[count] == ',') {
words.push_back(in);
in = "";
}
count++;
}
That will load the vector, ready for you to do all of the arcane and bizarre things you intend to do to it! :)
well here's what the programming principles and practices using c++ book is asking "write a program that finds the min, max, mode of a sequence of strings" is there a way that you can store the words from the string in the vector, i know when i run the program it evaluates just the string that's why i get one, im trying to store the words from the string in the vector, but i appreciate the help and will try your suggestions.