I am new to C++ coding. I want to know how hash_map and list can work together.

My requirement is:
I have a structure with address elements, name
My hash key should be name of address object.
Using the key I should find out structure.
I have dynamic list for address object.

I am got struck up getting hash values from hash_map iterator.
Can anyone help me in this regard?

I wrote some code, but it is not complete

#include <iostream>

using namespace std;
using namespace __gnu_cxx;

typedef struct
    char        strAddrObjName[20];
    char        strStartIP[16];
    char        strInfo[128];
} AddObject;

list<AddObject> addrObj;
void setaddrobj()
    int i = 0;
    AddObject temp;

    for(i = 0; i <3; i++)
        printf("Enter name: \n");

        printf("Enter IP: \n");
        scanf("%s", temp.strStartIP);

        printf("Enter Info: \n");

struct eqstr
    bool operator()(const char* s1, const char* s2) const {
        return (strcmp(s1,s2) == 0);
int main() {

    hash_map<const char*, AddObject , hash <const char *>, eqstr> columns;
    list<AddObject>::iterator it1;
    for(it1 = addrObj.begin(); it1 != addrObj.end(); ++it1)
        columns[(*it1).strAddrObjName] = *it1;
        printf("%s =  %s\n",columns[(*it1).strAddrObjName].strAddrObjName, columns[(*it1).strAddrObjName].strStartIP);

    printf("Columns hash_map size %i\n",columns.size());
    hash_map<const char*, AddObject, hash <const char *>, eqstr>::iterator it;

    for(it=columns.begin(); it != columns.end(); it++)
        printf(" %s\n", (*it)[*(it1).strAddrObjName].strStartIP);

I am getting error:
In function 'int main()':
60: error: 'struct std::_List_iterator<AddObject>' has no member named 'strAddrObjName'

Thanks in advance

Line 60:

printf(" %s\n", (*it)[*(it1).strAddrObjName].strStartIP);
should be
printf(" %s\n", (*it)[(*it1).strAddrObjName].strStartIP);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.