獲得不知道維度的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*);
相關文章
相關標籤/搜索