0

I'm a little new to maps (and c programming in general) and am trying to insert some values into a map that takes a string as a key, and a paired <double,double> as the corresponding values.

When I try and compile the code, I am presented with the error:

error: expected primary-expression before ‘,’ token
  values.insert(make_pair(string, pair<double,double>("test", 0.123456,0.98765 ) ) );
                                      ^
std::map<std::string, std::pair<double, double> > values;
values.insert(make_pair(string, pair<double,double>("test", 0.123456,0.98765 ) ) );

Do I need to utilise the iterator type in order to do this? Otherwise I have a feeling it's how I have structured this: "test", 0.123456,0.98765.

Shawn
  • 47,241
  • 3
  • 26
  • 60
  • 2
    That's not C. Please change the tags, or use the correct compiler. – wildplasser Nov 20 '20 at 01:21
  • 2
    Start by making a map of `string --> double` and once you have figured out how to do it properly, figure how to create a pair alone and finally figure out how to use them together. One can easily notice that you use ( instead of < after `make_pair`. Also, you try to pass 3 parameters in the innermost parenthesis while both `make_pair` and `pair` constructor have 2 parameters. – Phil1970 Nov 20 '20 at 01:39

1 Answers1

0

Solution:

values.insert(make_pair("test",make_pair(0.12312312, 0.56756756)));

    cout << values.size() << endl;

    for(map<string, pair<double,double> >::const_iterator it = radar_values.begin(); it != values.end(); it++)
    {
        cout << it->first << endl;
        cout << it->second.first << endl;
        cout << it->second.second << endl;
    }

Reference: How can I print out C++ map values?