I need to store strings in key value format. So am using Map like below.
#include<map>
using namespace std;
int main()
{
map<string, string> m;
string s1 = "1";
string v1 = "A";
m.insert(pair<string, string>(s1, v1)); //Error
}
Am getting below error at insert line
error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string'
I tried make_pair function also like below, but that too reports the same error.
m.insert(make_pair(s1, v1));
Pls let me know what's wrong and what's the solution for above problem. After solving above problem, can i use like below to retrieve value based on key
m.find(s1);
To insert the data in the map insert() function in the map is used. It is used to insert elements with a particular key in the map container. Parameters: It accepts a pair that consists of a key and element which is to be inserted into the map container but it only inserts the unique key.
You can use the Add Data button on the ArcMap toolbar to add data to your map. Click Add Data, browse to the data you want to add, then click Add. The data is added to the table of contents, but you'll still have to geocode the data's attribute table on the map to make it available for customer or store setup.
The standard solution to add values to a map is using the put() method, which associates the specified value with the specified key in the map. Note that if the map already contains a mapping corresponding to the specified key, the old value will be replaced by the specified value.
A map can be declared as follows: #include <iostream> #include <map> map<int, int> sample_map; Each map entry consists of a pair: a key and a value. In this case, both the key and the value are defined as integers, but you can use other types as well: strings, vectors, types you define yourself, and more.
I think you miss a #include <string>
somewhere.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With