我有一個簡單的while循環,我試圖實現,但對於我的生活無法弄清楚我失蹤。我在上面已經currentuser初始化爲-1一個簡單的C++雖然循環不工作
while(currentuser = -1){
cout << "Enter user ID: ";
cin >> id;
currentuser = search(a, length, id);
}
我的搜索功能是這樣的:
int search (User a[ ], int length, string userID){
User u;
string tempid;
int templegnth; //I ignore length for now as I will use it later
for(int i=0; i<50; i++){
tempid = a[i].getID();
templegnth = tempid.length();
if((tempid == userID)){
return i;
}
}
return -1;
}
我知道它的東西很簡單,但答案逃脫我現在。
將其更改爲'而被拋出(currentuser == -1)''注意'== 。如果不是這樣,你可能會考慮實際描述問題並提出問題。 – tenfour
你書中的哪一章清楚地區分=操作符和==操作符?嗯... – Sebivor