I am trying to write a C++ solution for a problem which is written C, I have learnt C++ very long ago(may be 15 years), and the way C++ is evolved
now is kind of taking long to understand and not easy as 'C' to develop a solution.
Would request any experts help in solving the problem .

Actually, the problem is quite big , but i broke down into small , so i that i can reuse from learnings here.

I have already started with a small class here to store a list of strings and print them.

But what i need is some good C++ way to store pre-defined enities and then create a mapper dynamically based on these entities.

for example in C i can do it this way

enum e_countries {GGG=0,AAA,WWW,FFF,III};
typedef struct Country_t{
    char name[SIZE];
    char flag[SIZE];
    char head[SIZE];
    enum e_countries e;

Country listOfCountries[] = { 
// Create Mapper , for easy and fast accessing of elements based on key 
hashsum = calc_hashsum(listOfCountries[cindex].name);
key = hashsum % (numOfCountries);

// some of methods i can use on mapper later 
    hashsum = calc_hashsum(nameofsomecountry);
    key = hashsum % (numOfCountries);
    return strcmp(nameofsomecountry,GetCountry(key));

C++ Solution:

#include <list>
#include <iostream>
#include <string>
#include <iterator>
#include <algorithm>

class Country
    std::string name;
    std::string flag;
    std::string head;
    Country(std::string countryName, std::string flagName,std::string headName) :
    name(countryName), flag(flagName), head(headName)

void Print();

std::list<Country> listofCountries ={ Country("Country1","Flag1","Head1"), Country("Country2", "Flag2","Head2"), Country("Country3", "Flag3","Head3")};

Country ::~Country(){}
void Country::Print()
    std::list<Country>::iterator it;
    for (it = listofCountries.begin(); it != listofCountries.end(); it++)
        std::string name = it->name;
        std::string flag = it->flag;
        std::string head = it->head;
        //Print the contents
        std::cout <<" C:" << name <<" F:" << flag <<" H:" << head << std::endl;

int main()
    Country P1;
    return 0;

The class needs to support these
1) Cretae a map with the key as country name
2) Strore Unique Elements:
i want to have country names unique, so i will check the new country with
all the existing countries , and store only if does not existing

Pick one language and go with that. It is very confusing trying to port software from one language to another.

C is not as good as C++ for complex software but it is quicker to write C code as it is simpler though has less type checking than C++ so more type errors can creep in.

Use lint to check syntax of C and find errors that compiler misses.

It is wise to create modules in C code or C will become spaghetti code and very hard to manage.

C code runs much faster than C++ code so if speed is important use C otherwise C++.

You seem to write top down procedural software.
Think bottom up.
Sometimes writing many small routines that reuse each other is more efficient than a monolithic program that is very opaque and hard to debug like your code above.

You program like a beginner: you stuff as many instances into variables as possible without thinking about schema or data structure. This creates very opaque poor quality software.

Clean it up and only put bare bones into data so it is not overloaded with extraneous data that is not relevant.
Don't bloat your code. This code is bloated.

Run a spell-checker on your posts. Your post is full of English typos and grammatical errors with missing words. It is hard to read.

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.