#include <stdio.h>
#include <map>
struct temp
{
int x;
int id;
};
int main()
{
temp t;
int key;
typedef std::multimap<int,struct temp> mapobj;
t.x = 10;
t.id = 20;
key=1;
mapobj.insert(pair<int,struct>key,t);
//mapobj.insert(1,t);
return 0;
}
I am new to STL multimap, I'm trying to insert my structure data inside the multimap but I get this error:
main.cpp:25:11: error: expected unqualified-id before ‘.’ token
mapobj.insert(pair<int,struct temp>key,t);
^
seeking your suggestion on this.
I think you need to make some minor code changes to fix the compile error as follows:
Here is the new code that compiles successfully:
#include <stdio.h>
#include <map>
struct temp
{
int x;
int id;
};
int main()
{
temp t;
int key = 1; // You should initialize the key
std::multimap<int,struct temp> mapobj; // I fixed this line
t.x = 10;
t.id = 20;
key=1;
mapobj.insert(std::pair<int,struct temp>(key,t)); // I fixed this line
//mapobj.insert(1,t);
return 0;
}