vendredi 27 février 2015

Using String to change Struct Variable?


Can I change the variable of a struct using a string? Sounds confusing, I will try and write an example.



struct test {
int testvar = 5;
} someone;

string testin;
cin >> testin;
int testint;
cin >> testint;

testin.testvar = testint;


What I'm trying to say is if when they entered the "testin" variable as "someone" then someone.testvar would equal whatever they put in for testint.




Aucun commentaire:

Enregistrer un commentaire