获得不知道维度的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"
};

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

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

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

char *words[] = {"stately", "plump", "buck"};
size_t words_size = sizeof(words)/sizeof(char*);
相关文章
相关标签/搜索