我的代码使用了我认为是简单的while循环。它检查这个randCard是否已经存在于我拥有的向量中,如果存在,则创建一个新的randCard。
我在循环中添加了cout语句,试图找出它正在运行的进程,发现它只在while循环中运行,而没有嵌套的for循环。问题如下:
bool isSame = true;
//Make sure they don't be the same cards
while (isSame){
cout << "While entered" << endl;
for(int i = 0; i < notToUse.size(); i++){
if(randCard == notToUse.at(i)){
randCard = rand() % 24;
}
cout << "First for ran" << endl;
}
for (int i = 0; i < notToUse.size(); i++){
if (randCard == notToUse.at(i)){
cout << "Recheck loop" << endl;
break;
}
else{
cout << "Else ran" << endl;
isSame = false;
}
}
}randCard来自于一类类型卡片。向量notToUse由已经使用过的卡片索引组成。end cout语句最终如下所示:
While entered
While entered
While entered
While entered
While entered似乎连for循环都没有被访问过。我该如何解决这个问题呢?
发布于 2019-05-03 07:05:28
对于任何可能偶然发现这一点的人,答案都在评论中得到了解决。向量的大小为0,因此for循环甚至不会运行。
https://stackoverflow.com/questions/55961241
复制相似问题