Name a variable with the value of another variable?

Hi! Something's just crossed my mind: Is it possible to create a variable and somehow name it with the value of another variable?

For example:

-The user is prompted to type a word. Eg: "dog"

-Then ...somehow... the programme takes this word and creates a new variable called "dog".
No, it is only possible with interpreted languages like PHP.
no because the compiler would see it as ambiguous and if you put a stray string in your program without a semicolon you would get an error.
closed account (o1vk4iN6)
You can use a hash table which can be used to relate a value to a string key.

This way a string can be associated with a value. I think people are misunderstanding what you want to do. Perhaps you are creating your own interpreter ?

What it sounds like is that you want to add a new variable to the source code during runtime, which obviously doesn't make sense for a language like C++. How can this variable be referenced and used if the name can't be determined at compile time ? So perhaps you might want to rephrase the question with an example or is this what you mean ?
Topic archived. No new replies allowed.