map<string, string> how to insert data in this map?

google maps street view
bing maps
mapquest app
route map
my maps
driving directions
world map
mapquest mileage

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);

I think you miss a #include <string> somewhere.

Official MapQuest, Official MapQuest website, find driving directions, maps, live traffic updates and road conditions. Find nearby businesses, restaurants and hotels. Explore! Map multiple locations, get transit/walking/driving directions, view live traffic conditions, plan trips, view satellite, aerial and street side imagery. Do more with Bing Maps.

Could you try this:

#include<string>

It seems the compiler doesn't know how to compare strings. Maybe she doesn't know enough about strings yet, but is too focused on your map to figure that out ATM.

Get Driving Directions, Live Traffic & Road Conditions, Map; Get Directions; Route Planner; Book Hotels, Flights, & Rental Cars; Relaunch tutorial hints NEW! Create a custom My Map; Share or Embed Map; Print your  Official MapQuest website, find driving directions, maps, live traffic updates and road conditions. Find nearby businesses, restaurants and hotels. Explore!

Try m[s1] = v1; instead.

Maps, Map multiple locations, get transit/walking/driving directions, view live traffic conditions, plan trips, view satellite, aerial and street side imagery. Do more with​  Get directions, maps, and traffic for Beijing, Hebei. Check flight prices and hotel availability for your visit.

You have several possibilities how store strings in key value format now:

m["key1"] = "val1";
m.insert(pair<string,string>("key2", "val2"));
m.insert({"key3", "val3"}); // c++11

And traverse it in c++11:

for( auto it = m.begin(); it != m.end(); ++it )
{
  cout << it->first; // key
  string& value = it->second;
  cout << ":" << value << endl;
}

Map, The Map object holds key-value pairs and remembers the original insertion order of the keys. Beijing Transportation Map. Beijing is an important transport hub in North China with numerous international/regional flights to get there. The major airports in Beijing include Beijing Capital International Airport, Beijing Nanyuan Airport, and Beijing Daxing Airport, which is about to open in September, 2019.

Here is the way to set up map<...,...>

static std::map<std::string, RequestTypes> requestTypesMap = {
   { "order",       RequestTypes::ORDER       },
   { "subscribe",   RequestTypes::SUBSCRIBE   },
   { "unsubscribe", RequestTypes::UNSUBSCRIBE }
};

Array.prototype.map(), The map() method creates a new array populated with the results of calling a provided function on every element in the calling array. China Beijing maps include city downtown and tourist map with districts' and streets' location. Maps of subways, train station and airport transfer are also listed.

MAP International Home, We can make this statement because MAP receives generous donations of medicines and health supplies and has relatively low expenses. Last year alone, we  Here is the map showing the location of all the 16 districts. Beijing Districts Map Main Districts in Beijing. Beijing has 16 districts in total. The downtown area of Beijing includes Dongcheng, Xicheng, Chaoyang, Fengtai, Shijingshan, and Haidian. They are also where the main attractions locate.

Beijing Haidian District Map – Beijing Haidian district lies towards the northwestern part of the greater urban area. Haidian district is the second-largest district in urban Beijing with 431 square km in area, home to most universities where many of its inhabitants are college students.

Haidian Haidian is a large district in the north-west of Beijing.Haidian has been a major beneficiary of the recent subway expansions: lines 4, 10, and 13 make it easier to reach Haidian's busier areas by public transport.

Comments
  • This made the code compiled. But am wondering why it didn't give error when i said string s1 = "1"; Only upon calling insert it gives error.
  • @bjskishore123: Perhaps you have another class whose name is string that somehow collides with std::string ?
  • I have tested this on the latest VS 2012 version and it does the same thing. It's very confusing and peculiar that it doesn't complain about string not being defined.
  • Oh, interesting! Is the compiler she? Allright, I can agree on that. :) - Just like our Mother Nature and Milkyway Galaxy (in Sanskrit: Shi-shu-maa-ra = She-dolphin).
  • And this gives you no way to tell if you inserted a new node or updated a pre-existing one.
  • m.insert({"key3", "val3"}); // c++11 helped me