得到不知道维度的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*);

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值