c****e 发帖数: 3522 | 1 比如,我有个string a="abc", 还有个var abc
怎么通过a 把abc的值 调用出来 ?
c,fortran语言都可以 |
g*****g 发帖数: 34805 | 2 Probably not for C or fortran, any language with
reflection capability will do it, like Java or C#
【在 c****e 的大作中提到】 : 比如,我有个string a="abc", 还有个var abc : 怎么通过a 把abc的值 调用出来 ? : c,fortran语言都可以
|
c****e 发帖数: 3522 | 3 把variable的名字,变成string如何呢
这样就可以了
【在 g*****g 的大作中提到】 : Probably not for C or fortran, any language with : reflection capability will do it, like Java or C#
|
n*e 发帖数: 50 | 4 in python:
def foo():
print 'Hello!'
eval('foo()',globals())
【在 c****e 的大作中提到】 : 比如,我有个string a="abc", 还有个var abc : 怎么通过a 把abc的值 调用出来 ? : c,fortran语言都可以
|
r****t 发帖数: 10904 | 5 别人问的是在 static language 里面
【在 n*e 的大作中提到】 : in python: : def foo(): : print 'Hello!' : eval('foo()',globals())
|
s***e 发帖数: 122 | 6 做个table就可以了。
比如说这样
char * keys[2] = {"abc", "def"};
int abc;
int def;
int * values[2] = {&abc, &def};
然后你找出你的a在keys里面的下标,就查出它的value了
【在 c****e 的大作中提到】 : 比如,我有个string a="abc", 还有个var abc : 怎么通过a 把abc的值 调用出来 ? : c,fortran语言都可以
|
l******u 发帖数: 1174 | 7 Not possible in a truly static language (one in which a compiler can check
all type errors).
【在 r****t 的大作中提到】 : 别人问的是在 static language 里面
|
c*****t 发帖数: 1879 | 8 You should tell us what you are really trying to do.
【在 c****e 的大作中提到】 : 把variable的名字,变成string如何呢 : 这样就可以了
|
p***o 发帖数: 1252 | 9 most likely some simple scripting support
std::map should be enough ...
【在 c*****t 的大作中提到】 : You should tell us what you are really trying to do.
|
O******e 发帖数: 734 | 10 There is the # operator in cpp/fpp, but I don't think that this is
what you want.
This would be preprocessed, not C or Fortran language proper.
#define show_int(x) printf(#x" = %d\n",x)
#include
int main () {
int x=5;
show_int(x);
return(0);
}
#define show_int(x) print'(a," = ",i0)',#x,x
program main
integer::x=6
show_int(x)
stop
end program main
【在 c****e 的大作中提到】 : 把variable的名字,变成string如何呢 : 这样就可以了
|