how to initialize associate data in map?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • forrestarrow
    New Member
    • Sep 2007
    • 2

    how to initialize associate data in map?

    Hi everyone,
    I used STL map in my code and I am wondering is the associate data automatically initialized or not. The reason I am asking is that I have two arrays of data, and the first array is index, and second array is my data corresponding to the index. But there are duplicate indexs and I want to add up the data of duplicate index.

    For example;
    map<int index, double data> mid;
    mid[index] += data;

    So I want to know at beginning, is the data are initialized to 0. or I have to do it myself? Thanks in advance.

    Jingbin
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    Originally posted by forrestarrow
    Hi everyone,
    I used STL map in my code and I am wondering is the associate data automatically initialized or not. The reason I am asking is that I have two arrays of data, and the first array is index, and second array is my data corresponding to the index. But there are duplicate indexs and I want to add up the data of duplicate index.

    For example;
    map<int index, double data> mid;
    mid[index] += data;

    So I want to know at beginning, is the data are initialized to 0. or I have to do it myself? Thanks in advance.

    Jingbin
    mpas dosent allow duplicate indexes, only multi-map allow duplicate index.

    Raghu

    Comment

    • keerthiramanarayan
      New Member
      • Nov 2007
      • 13

      #3
      The map in your case will be initialized to 0.00 . However it is not the case with types such as strings or user classes. which tend to by null(0). So you should be careful.

      Comment

      Working...