stlmap - Does map<key, data> in C++ STL support native data types like Structures? -


i trying write this. question how map key native data type structure. wrote snipped couldn't compile it. have ideas on how achieve thing?

#include <map> #include <iostream>  typedef struct _list {   int a,b; }list; map<int,list> test_map;  int main(void) {   cout <<"testing"<< endl;   return 0; } 

a number of problems here:

  • you're missing either using::std or std::map, compiler doesn't know map<int,list> means.

  • assuming have using namespace std declaration, typedef list might collide stl collection of same name. change name.

  • your typedef struct _tag {...} tag; construct archaic holdover 80's. not necesarry, , frankly rather silly. gets nothing.

here's code fixed:

#include <map> #include <iostream>  struct mylist {   int a,b; };  std::map<int,mylist> test_map;  int main(void) {   std::cout <<"testing"<< std::endl;   return 0; } 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -