Map memeory issue in c++

Hi,
I was loading data from database and insert into map. When I tried to print map
size and data. it is still showing size 1 and only last row is printitng.
all previous data is overwritten and contain last value. Any Pointer in this
issue. I have change the name of variable because of company issue.

I have done some check Point also.
1. all key value is unique.

typdef long_char char[38];

for(int j=0;j<31;j++)
{
sample_enum param_sub_type = result_set[j];
long_char param_name;

strncpy(param_name,result_set[j],sizeof(param_name));
input_status_cd.insert(std::pair<long_char,sample_enum >(param_name,param_sub_type)); /*Insert Into Map */
}
/*Printing Size of map */
input_status_sd::size_type input_status_cd_size;
etlog_msg(ETLOG_INFO, GetProgramName(), retcode, __FILE__,__LINE__,"[ intput_status_cd_size :] [%d]",intput_status_cd.size());
Last edited on
It can't work because you're using an array as a key, so you don't have the any operator for comparison that map can use. Maybe you want to put a string instead. I think param_name has always the same address throughout the entire loop, so every time you're just overwriting the same element in the map (and then size=1).

HTH, but use code tags next time ;)
Last edited on
Topic archived. No new replies allowed.