简体   繁体   中英

String Value is the name of an int pointer

struct token{ string type; string value;};

//Global variables:
int reg[10]={-1,...,-1};
int* R0 = reg;

... down in some func...
cout<< *(R0)<< endl;//OUTPUTs -1
int valInR0= *reinterpret_cast<int*>(&token.value) //contains string "R0"

The issue is that I have a struct that has a member of string called value to store different names and when I try to take the name of an int pointer out of the string I am unable to figure out how to make it reference back to the int pointer and dereference its value.

As in the above example taking the string val "R0" out of my struct and then using it to access the int *RO is what I am trying to accomplish to no success.

谢谢你的回答,我决定操作这个名字,所以如果 R5 被存储,我会撕掉 R,将 5 存储在一个 int 中,然后可以使用它作为偏移量来访问像*(reg+5) ,像这样:

int val = (token.value[1]-ASCII);// ASCII is 48 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM