Is it really impossible to make a string into a variable in c++ -


Both the answers say that you can not use a string after compiling time. However, they mention that high level languages ​​such as Python as I understand it, Python has been written from C.

So if Python is written in C, and it can use the string as a variable, then why do not people do it in whistle.

I think the question is not clear. By analogies in comments,

If Python is composed of C, then I think that some functions are written that allow Python to be dynamic. So why not the functionality can be written without all other parts of Python.

CPththon implementation - implementation of Python written in C. - C language can be used for a certain type of variable lookup Which uses Python to behave like a python and does not say, C or Basic.

So, you do not expect C ++ just compiler to recognize C or String-named variable lookup, because it's C / C + + Not part of the language End product - compiled execution - However, this concept will support.

For example, in C ++, using Boost:

  std :: map & lt; Std :: string, boost: variant & lt; Std :: string, int & gt; & Gt; _; _ ["Name"] = "user"; _ ["Index"] = 1 938107; Std :: cout & lt; & Lt; _ ["Name"] & lt; & Lt; _ ["Index"] & lt; & Lt; Std :: endl;  

Output:

  user1938107  

You can also interoperate with the regular variable known to the compiler, But if there are no closed-shelf classes to help you out.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -