User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 426,323 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,267 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums

Maps in VC++ 6.0

Join Date: Sep 2004
Posts: 6,324
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 28
Solved Threads: 458
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: Maps in VC++ 6.0

  #7  
Sep 19th, 2005
>as my version of VC++ doesn't recognize the '::mapped_type'
That should teach you to use standard options when they exist:
#include <iostream>
#include <map>
#include <utility>

using namespace std;

typedef pair <const int, int> cInt2Int;

int main()
{
   map<int, int> m1;
   map<int, int>::value_type value1;
   map<int, int>::iterator pIter;
   int key1, mapped1;
   
   // value_type can be used to pass the correct type
   // explicitly to avoid implicit type conversion
   m1.insert ( map<int, int>::value_type ( 1, 10 ) );

   // Compare other ways to insert objects into a map
   m1.insert ( make_pair ( 2, 20 ) );
   m1[3] = 30;

   // Initializing key1 and mapped1
   key1 = m1.begin()->first;
   mapped1 = m1.begin()->second;

   cout<<"The key of first element in the map is "<< key1 <<".\n";
   cout<<"The data value of first element in the map is "<< mapped1 <<".\n";

   cout<<"The keys of the mapped elements are:";
   for ( pIter = m1.begin(); pIter != m1.end(); pIter++ )
      cout<<" "<< pIter->first;
   cout<<".\n";

   cout<<"The values of the mapped elements are:";
   for ( pIter = m1.begin(); pIter != m1.end(); pIter++ )
      cout<<" "<< pIter->second;
   cout<<"."<<endl;
}
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
Reply With Quote  
All times are GMT -4. The time now is 10:58 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC