今天查资料,找到一个大佬写的内容,解决了我的问题,就是求string[ ]里的元素个数,使用sizeof(strKeyword)/sizeof(strKeyword[0]
int main()
{
string strKeyword[] = {"class","void"};
for(int i = 0;i<sizeof(strKeyword)/sizeof(strKeyword[0]);i++)
{
cout<<strKeyword[i]<<endl;
}
return 0;
}
本示例是个测试,是打算自己写词法分析的,但目前只想到一个比较笨的办法,先写写看。