mercredi 19 avril 2017

get member values of structs c++ where member variables are stored in string [duplicate]

This question already has an answer here:

I want to get the value of a member but the member name is stored as string. How can I get the member value ?

struct Person
{
    string name = "MyName";
    int age = 15;
}

int main()
{
    struct Person p;
    string s= "name"; 
    cout<<p.s<<endl; //This will give error since s is not member of struct
}

Is there a way to get this done?





Aucun commentaire:

Enregistrer un commentaire