How to insert into std::map.

Posted by Knowing me knowing you on Stack Overflow See other posts from Stack Overflow or by Knowing me knowing you
Published on 2010-04-26T11:07:22Z Indexed on 2010/04/26 11:13 UTC
Read the original article Hit count: 176

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about c++

Related posts about map