How do you take input from a user and use that input to determine what information in a class to use. Here's an example that doesn't work, but hopefully you understand what I am trying to do from this.
class hello {
string name;
int size;
};
int main() {
string classname;
hello world;
world.name = "Earth";
world.size = 100;
hello people;
people.name = "Everyone";
people.size = 2;
cin >> classname;
cout << classname.name;
return 0;
I want to take the user's input, classname, and use it to determine which instance of hello to use. The only way I was able to do this before was to use an if statement like:
if (classname == "world") {
cout << world.name;
}
if (classname == "people") {
cout << people.name;
}
but I was working on a project where I had over a hundred different options and that is a lot of if statements to write so I tried doing it differently. After hours upon hours of looking, I still have had no luck finding a way to do this so any info would be greatly appreciated.