#include <iostream>

#include <map>

#include <string>

main(int argc, char* argv[])

{

std::multimap<int, int> test;

test.insert(std::pair<int,int>((int)1, (int)3));

}

CC mapTest.C

"mapTest.C", line 51: Error: Could not find a match for std::multimap<int, int, std::less<int>, std::allocator<std::pair<const int, int>>>::insert(std::pair<int, int>) needed in main(int, char**).

Any help would help.

Thanks

#include <map>

#include <string>

main(int argc, char* argv[])

{

std::multimap<int, int> test;

test.insert(std::pair<int,

}

CC mapTest.C

"mapTest.C", line 51: Error: Could not find a match for std::multimap<int, int, std::less<int>, std::allocator<std::pair<c

Any help would help.

Thanks

```
// multimap_insert.cpp
#include <map>
#include <iostream>
int main( )
{
using namespace std;
multimap <int, int>::iterator m1_pIter, m2_pIter;
multimap <int, int> m1, m2;
typedef pair <int, int> Int_Pair;
m1.insert ( Int_Pair ( 1, 10 ) );
m1.insert ( Int_Pair ( 2, 20 ) );
m1.insert ( Int_Pair ( 3, 30 ) );
cout << "The original key values of m1 =";
for ( m1_pIter = m1.begin( ); m1_pIter != m1.end( ); m1_pIter++ )
cout << " " << m1_pIter -> first;
cout << "." << endl;
cout << "The original mapped values of m1 =";
for ( m1_pIter = m1.begin( ); m1_pIter != m1.end( ); m1_pIter++ )
cout << " " << m1_pIter -> second;
cout << "." << endl;
m1.insert ( Int_Pair ( 1, 10 ) );
// The hint version of insert
m1.insert( --m1.end( ), Int_Pair ( 4, 40 ) );
cout << "After the insertions, the key values of m1 =";
for ( m1_pIter = m1.begin( ); m1_pIter != m1.end( ); m1_pIter++ )
cout << " " << m1_pIter -> first;
cout << "," << endl;
cout << " and the mapped values of m1 =";
for ( m1_pIter = m1.begin( ); m1_pIter != m1.end( ); m1_pIter++ )
cout << " " << m1_pIter -> second;
cout << "." << endl;
m2.insert ( Int_Pair ( 10, 100 ) );
// The templatized version inserting a range
m2.insert( ++m1.begin( ), --m1.end( ) );
cout << "After the insertions, the key values of m2 =";
for ( m2_pIter = m2.begin( ); m2_pIter != m2.end( ); m2_pIter++ )
cout << " " << m2_pIter -> first;
cout << "," << endl;
cout << " and the mapped values of m2 =";
for ( m2_pIter = m2.begin( ); m2_pIter != m2.end( ); m2_pIter++ )
cout << " " << m2_pIter -> second;
cout << "." << endl;
}
```

easier to handle than multimap<int, int> is std::map<int, std::vector<int> >.

```
std::map<int, std::vector<int> > test;
test[1].push_back(3);
test[1].push_back(5);
```

Sara

I tried using ::value_type(); worked for multimap<int,int> but got errors for class type multimap<long, FDProcess*>; where FDProcess is the class.

"/opt/SUNWspro/prod/includ

"/opt/SUNWspro/prod/includ

"/opt/SUNWspro/prod/includ

"/opt/SUNWspro/prod/includ

"/opt/SUNWspro/prod/includ

"/opt/SUNWspro/prod/includ

"/opt/SUNWspro/prod/includ

"/opt/SUNWspro/prod/includ

"/opt/SUNWspro/prod/includ

"/opt/SUNWspro/prod/includ

"/opt/SUNWspro/prod/includ

"/opt/SUNWspro/prod/includ

4 Error(s) detected.

I indeed liked both vector and value_type solutions. From code readable perspective vector solution is perfect but I liked value_type the most.

Thanks

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.

In your compiler, for std::multimap<int, int>, the value type is std::pair<const int, int>, and not std::pair<int, int>.

So try using :

Open in new window

instead of :

Open in new window