由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 怎么把string变为一个variable的名字 ?
相关主题
C++中size_type怎么处理?How to define a data type of 1 bit size?
eval (expr, envir=, enclose=) 求解答C++小问题
awk or sed questiona string define question (c++)
perl 怎样检测一个strig是否是valid的JSON string要不要学习 scripting languages such as Python?
为什么说Javascript 是披着C 外衣的Lisp?[合集] static const代替define的performance tradeoff在哪里?
Help -- How to output error messages to a file for scripts called by system calls???Need help on choosing the language
FORTRAN 90 菜鸟问题Multilanguage Support?
另一个Fortran 问题我的matlab 抽风了。。。。
相关话题的讨论汇总
话题: int话题: string话题: abc话题: fortran话题: variable
进入Programming版参与讨论
1 (共1页)
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如何呢
: 这样就可以了

1 (共1页)
进入Programming版参与讨论
相关主题
我的matlab 抽风了。。。。为什么说Javascript 是披着C 外衣的Lisp?
Please help: sort XML with LinqHelp -- How to output error messages to a file for scripts called by system calls???
replace document body,but js does not runFORTRAN 90 菜鸟问题
为什么从txt文件里拷贝script到front page 里面时空格都变成了%20 ?另一个Fortran 问题
C++中size_type怎么处理?How to define a data type of 1 bit size?
eval (expr, envir=, enclose=) 求解答C++小问题
awk or sed questiona string define question (c++)
perl 怎样检测一个strig是否是valid的JSON string要不要学习 scripting languages such as Python?
相关话题的讨论汇总
话题: int话题: string话题: abc话题: fortran话题: variable