In code below:
map<string,vector<int>> create(ifstream& in, const vector<string>& vec)
{
/*holds string and line numbers into which each string appears*/
typedef map<string,vector<int>> myMap;
typedef vector<string>::const_iterator const_iter;
myMap result;
string tmp;
unsigned int lineCounter = 0;
while(std::getline(in,tmp))
{
const_iter beg = vec.begin();
const_iter end = vec.end();
while (beg < end)
{
if ( tmp.find(*beg) != string::npos)
{
result[*beg].push_back(lineCounter);//THIS IS THE LINE I'M ASKING FOR
}
++beg;
}
++lineCounter;
}
return result;
}
How should I do it (check line commented in code) if I want to use insert method of map instead of using operator[]?
Thank you.