早教吧 育儿知识 作业答案 考试题库 百科 知识分享

下面代码中的“if(key[i].compare(c)==0)return1;”这句语句是什么意思stringkey[15]={"begin","end","if","then","else","while","write","read","do","call","const","char","until","procedure","repeat"};intIskey(stringc){//关键字判

题目详情
下面代码中的“ if(key[i].compare(c)==0) return 1;”这句语句是什么意思
string key[15]={"begin","end","if","then","else","while","write","read",
"do","call","const","char","until","procedure","repeat"};
int Iskey(string c){ //关键字判断
int i;
for(i=0;i
▼优质解答
答案和解析
compare是CString的成员函数,比较两个字符串的
【Zero if the strings are identical, < 0 if this CString object is less than lpsz, or > 0 if this CString object is greater than lpsz.】
if(key[i].compare(c)==0) return 1;
是key[i]与c比较,相等,直接返回1;
不等,一直不断比较,都不等,返回0
因此,这段代码就是判断c是否是关键字之一.