c++ - Using string vector in map -


i have map string key , second atribute should vector.

declaration:

map <string, vector<string> > subjects; 

and when want use adding values.

subjects[s] = new vector<string>; subjects[s].push_back(n); 

s , n strings. got error first line. says error: no match ‘operator=’ (operand types ‘std::map<std::basic_string<char>, std::vector<std::basic_string<char> > >::mapped_type {aka std::vector<std::basic_string<char> >}’ , ‘std::vector<std::basic_string<char> >*’) . tried give pointer of vector map, doesn't help.

value of subjects type not pointer, can't allocate new it.

if n string type, call:

map <string, vector<string> > subjects;  std::string n("hello");  subjects[s].push_back(n); 

edit:

to print value map, need find element in map iterator vector.

auto = subjects.find(s);  if (it != subjects.end()) {     auto& vit = it->second;      (auto elem : vit)     {         cout << elem << endl;     } } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -