I have got some code that gets the most frequent words and puts them into a vector. I then sort the vector into numerical order and all this works fine. I then try to resize the vector to 10 so I can get the top ten that I want to sort by word.
I think the problem lies with part of my struct but i am not to sure here is the code i am using.
struct wordFreq
{
string word;
int count;
wordFreq(string str, int c): word(str),count(c) { }
};
words.resize(10);
Any help will be appreciated.
When resizing the vector, the function
resizeneeds to know the value for the new elements. Therefore, the callincludes a default argument of the form
wordFreq(), which is invalid in your case, since the classwordFreqdoesn’t have a default constructor.If no new elements are being created, use
eraseinstead ofresize.