Creating Int variable from char array

Hi,
I have a problem. I want to create an integer variable from char array.
Suppose you have an char array char a[]="Hello World". now i will give you a position like 6 then you have to create int W (W from array).
Please help me.
Last edited on
I don't understand completely, do you want the integer-value of the char at position 6? In that case all you need to do is int i = a[6];.
Last edited on
No, I want to make W as int variable. That is the variable name (as W) will come from string.........
It can't be done
Talk about metaprogramming. No, what you're asking to do isn't possible in C++. You must create a name for a variable before the program is compiled. You cannot create variables with a specific name at run-time, because those names don't exist at run-time. More importantly, why would you want to create variables of that name? There would be no way to keep track of anything.

EDIT:
maeriden wrote:
It can't be done
Ah, you beat me to it. Pretty much what maeriden said.
Last edited on
Thanks for answering my question.....
I was just curious to do that .
By the way thanks again.....
Topic archived. No new replies allowed.