cin<<a;
lets say the user enters 'i'
if i have a variable i,i want its variable to be displayed
So you mean:
int i = 1;
char a;
cin >> a; //user enters 'i'
and you want to display '1'? If so -> not possible. You could use arrays, vectors, maps are something to do something similar?
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
Yes, it is not possible. But ask your self: you you really need it? I never felt need of such a thing. The only close alternative is to use a std::map something like this:
int main()
{
using std::map;using std::string;using std::cout; using std::cin;
map<string,int> m;
m["i"]=1;
m["k"]=5;
m["ok"]=53;
string input;
cout<<"Enter a variable name";
cin>>input;
cout<<"You entered "<<m[input];
}
siddhant3s
Practically a Posting Shark
816 posts since Oct 2007
Reputation Points: 1,486
Solved Threads: 140
>What langage is reflection possible? atleast without a lot of difficulty?
Python and Lisp as far as I know.
siddhant3s
Practically a Posting Shark
816 posts since Oct 2007
Reputation Points: 1,486
Solved Threads: 140
What langage is reflection possible? atleast without a lot of difficulty?
Python for example (as already mentioned by siddhant3s).
But the real question is: Why would you want to do that? There's probably a better way to achieve your goal then switching to another language.
How about you tell us what you want from your program an maybe we can suggest some alternatives. ( as siddhant3s and Tom Gunn already did actually )
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
siddhant3s
Practically a Posting Shark
816 posts since Oct 2007
Reputation Points: 1,486
Solved Threads: 140