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 ;
}
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.
Input:
Output:
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.