Hi all ,i want to read from file vector of strings and write in another file the number of any word's frequency ,but before that i want to sort my vector;
here is my code
vector<pair1> myfunc(vector<string>& myvec1)
{
vector<pair1> mypair;
for(int i = 0; i < myvec1.size(); ++i)
{
pair1 temp = {myvec1[i], 1};
// You're already adding a new item.
// Before you pushback, shouldn't you check if there is a copy?
bool found = false;
for (int j = 0; j < mypair.size(); ++j)
if (p == mypair[j])
{
++(mypair[j].num);
found = true;
}
if ( !found ) // If not found. Found is still false
mypair.push_back(p); // add new item.
} // END FOR LOOP
// Just took care of this in above code.
// for(int i = 0; i < mypair.size();i++)
// for(int j=0;j<mypair.size();j++)
// {
// if(mypair[i].st==mypair[j].st)
// mypair[i].num++;
//
//
//
// }
return mypair;
}//; // You do not need semicolons at the end of functions.
// ONLY structs, protypes, and classes.