-1

this is for a personal use application in c++ for example:

class x                
{...};
int main()
{

string userinput;

cin>>userinput;

cin>>x."userinput";}

is something like this possible?

nunya
  • 11
  • 1

1 Answers1

0

If what you are talking about is allowing for the user to set variable names at runtime, then no. It is not possible in c++. Depending on what you are trying to achieve, there are a few ways around this.

If you just need the user to be able to access a small number of variables, all of which are known before hand, you can use a switch statement, or a bunch of if/elseifs

If you need to store a larger amount of variables the number of which may not be known at compile time, then there exists a number of data structures that exist just for this purpose. There are arrays, hash tables, linked lists and hundreds of variations on the above. These are all far too complex topics to cover in a single answer however.

Matt
  • 968
  • 2
  • 13
  • 22
  • No i do want to set variable name at runtime I want to input a particular variable at runtime which is selected by me. Using a switch case/if-else was something i considered but i though there might be a better solution so i asked here. I'll look into hashed tables and try to implement that. Thanks for the help! – nunya Mar 04 '17 at 12:26