【发布时间】:2019-03-31 14:27:48
【问题描述】:
如何在for循环中包含两个索引值测试条件?
我希望为数组语法解析一个字符串(分别找到'['和']'的位置)
string arrangements="a[1]";
所以我试图在一个 for 循环中进行时间复杂度的目的。 我试过了
for(int i=0; i<arrangements.size();i++){
if(arranements[i]=='['){
cout<<"square opening is at : "<<i<<endl;
while(arrangements[i]==']' ){
cout<<"square closing is at : "<<i<<endl;
i++;
}
}
}
我什至尝试过
for(int i=0; i<arrangements.size();i++){
while(arrangements[i]==']' && arrangements[i]=='['){
cout<<"square closing is at : "<<i<<endl;
i++;
}
}
}
对不起,我没有与任何人联系,所以谢谢你帮助好人。
【问题讨论】:
-
while(arrangements[i]==']'){=>while(arrangements[i]!=']'){ -
我建议研究如何编写一个适当的递归体面解析器或如何为您要解析的任何内容编写 BNF 语法,然后使用诸如 bison 之类的东西来生成语法分析器。或者,在琐碎的情况下,使用正则表达式。
-
@JesperJuhl 谢谢你的这些关键字,我现在可以去具体点了..
标签: c++ for-loop while-loop