得到不知道维度的string数组的维度

在项目中常用到一类数组,那就是不知道个数的数组,例如:

 

string ParamTable[] = {"frequency","ifbw","span","demodmode","afc","ifattmode","measuretime","detector",
"gainctrl","mgcvalue","squelchthreshold","recordshold","holdtime","dweltime","keeptime","rfattenuation",
"bandmode","xdb","betapercent","startfreq","stopfreq","step","scancount","levelrange",
"reflevel","displaymode","preamplifier","dfmode","dfbw","integrationtime","freqrange","qualityshold",
"levelshold","sholdlevel","rbw","vbw","sweeptime","polarization","modulation","antenna",
"if_fq","fixfq","iqdem","sr_md"
};

想得到里面元素的个数,也就是得到这个数组的维度,被困扰了很久,下面给出了一种办法,亲测有效

size_t words_size= sizeof(ParamTable)/sizeof(string);

这是用string的情况,下面是c语言的情况:

char *words[] = {"stately", "plump", "buck"};
size_t words_size = sizeof(words)/sizeof(char*);

 

posted @ 2015-12-18 13:51  shmilxu  阅读(554)  评论(0编辑  收藏  举报