RE: Stl map as a constant

  • From: "Ken Perry" <whistler@xxxxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Fri, 6 Jun 2008 12:21:04 -0700


You can not.  Stl maps are templates and currently c++ does not allow you to
declare and add to a template at declaration time.  So what you normally do
is declare it then add to it.  If you need an example of that the following
is a simple map program.


#include <iostream>
#include <string>
#include <map>

using namespace std;


int main(int argc, char* argv[])
{

// Here is the declaration of the map

map<string, string> mymap;
map<string, string>::iterator iter;
string addr,mail;

//just to show how you would stuff a string in the map
addr="bla@xxxxxxxxxxxxxx";
mail="bla bla bla bla bla\n";
mymap[addr]=mail;

addr="fargo@xxxxxxxxxxxxxxx";
mail="Where the heck am I\n";
mymap[addr]=mail;

addr="aloeyRubdown@xxxxxxxxxxxxxxx";
mail="Has any one seen the sticky table.\n";
mymap[addr]=mail;

cout << "This is the output of the map in order" << endl;

for(iter = mymap.begin(); iter != mymap.end(); iter++)
  {
  cout<<iter->first<<endl;
  }

return (0);
}
 

-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Sean Farrow
Sent: Friday, June 06, 2008 3:23 AM
To: programmingblind@xxxxxxxxxxxxx
Subject: Stl map as a constant

Hi: 
How can I declare an stl map and insert elements at declaration time.
Any help apreciated.
Sean. 
 

__________ Information from ESET NOD32 Antivirus, version of virus signature
database 3163 (20080606) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: