Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3282910
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:58:52+00:00 2026-05-17T19:58:52+00:00

this may be a simple problem, but i am not able to figure it

  • 0

this may be a simple problem, but i am not able to figure it out. I have structure like this.


struct emp 
{
  int empid;
  string fname;
}
emp e[10];

I have some data in e[10].


e[0].empid = 1 , e[0].fname = "tanenbaum"
e[1].empid = 2 , e[1].fname = "knuth"
.....

Now if i have given input command line like this:


emp , empid

Now i need to access the structure emp.empid. If i have 10 other structures, i need to access them, when the input gives like structure tag and structure member. Here i am not able to figure out how to attach string variables(emp, empid) to structure members(emp.empid). thanks in advance.
EDIT
Here is my program.


int main(int argc, char *argv[])
{
  char *tag_name = argv[1]; //emp (structure tag name)
  char *member_name = argv[2]; // empid (structure member name)
  int data = argv[3]; //value: 2
  /* I need some mechanism that will convert those tag_name.member_name
     to original structure memmber access
tag_name(emp).member_name(empid) == value (2) Is there any way to map like this */ return ; }

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T19:58:52+00:00Added an answer on May 17, 2026 at 7:58 pm

    EDIT: Using pointer to member operator you can achieve what you wanted.
    You need to create small database using std::map.

    Below is the working program.

    #include <iostream>
    #include <string>
    #include <map>
    using namespace std;
    struct emp 
    {
      int empid;
      int salary;
    };
    
    int main(int argc, char *argv[])
    {
        //member map stores member varialbe names and corresponding offsets.
        map<string, int emp::*> memberMap; //It can store offsets of only integer members.
    
        //tagMap stores tag names and object pointer
        map<string, emp *> tagMap;
    
        //Allocate for 10 records
        emp *e = new emp[10];
        //Store sample data in those records.
        for(int i = 0; i < 10; i++)
        {
            e[i].empid = (i+1) * 10;
            e[i].salary = (i+1) * 1000;
        }
    
        //Populate tag map with tag names and corresponding object pointers
        //As of now, we have only emp structure.
        //You can add more structures similar to below.
        tagMap.insert(pair<string, emp *>("emp", e));
    
        //Get the offsets of member variables of emp structure.
        int emp::*offset_empid = &emp::empid;
        int emp::*offset_salary = &emp::salary;
    
        //Populate member map with member names and corresponding offsets
        memberMap.insert(pair<string, int emp::*>("empid", offset_empid));
        memberMap.insert(pair<string, int emp::*>("salary", offset_salary));
    
        //Am passing tag name in argv[1], member name in argv[2] and record id in argv[3] from
        //command line
        string tagName = argv[1]; //tag name
        string memberName = argv[2]; //member name
        int recordId = atoi(argv[3]);//record id
    
        //Access member specified like below.
        cout<<"Employee details requested are : "<<endl;
        cout<<memberName<<"\t"<<(tagMap[tagName]+recordId)->*memberMap[memberName];
    
        //Free the allocated memory.
        delete []e;
    }
    

    Input:

    emp salary 2

    Output:

    Employee details requested are :
    salary 3000

    I hope you can understand the program using comments i wrote.

    Input: i am providing tagName, fieldName and recordId.

    Output: i am getting the requested field value from requested record id.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Now, this requirement may seem weird. But i would like to know how to
I'm going to come right out and say that I am not the worlds
My Problem: I am trying to developing a web application for currency traders. The
I'm trying to write an embedded ( NOT web, not enterprise ) content management
I'm fed up with this. I've been trying to just get a grip on
I'm trying to solve a problem that anonymous functions make much, much easier, and
I'm using Java. I want to have a setter method of one class that
What is the correct/best way of handling spaces and quotes in bash completion? Here’s
how to create a good plugin engine for standalone executables created with pyInstaller, py2exe
I've recently been working through a large codebase, refactoring and generally improving design to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.