-2
    vector<pair<int,set<string>>>m1;

I am trying to insert an element where each int will hold several strings using set. How to insert an element in this?

I tried like this.

    vector<pair<int,set<string>>>m1;
    int p,n,i;
    cin>>p>>n;
    string s[n];
    for(i=0;i<n;i++){
    cin>>s[i];
    m1.push_back(make_pair(p,insert(s[i])));
    }

But it shows error. Help much appreciated. Thanks!!

Joy Sinha
  • 11
  • 2

2 Answers2

0

make_pair needs to take a key/value pair, so the set should already exist.

set<string> s;

for(i=0; i<n; i++){
    {
    string str;
    cin >> str;
    s.insert(str)
    }

m1.push_back(make_pair(p, s));
acraig5075
  • 10,588
  • 3
  • 31
  • 50
0

Change

m1.push_back(make_pair(p,insert(s[i])));

to

m1.push_back(make_pair(p, set<string>{s[i]}));

The std::set must exist before you insert any element into it.

Ron
  • 14,674
  • 4
  • 34
  • 47
KostasRim
  • 2,053
  • 1
  • 16
  • 32