6
出於某種原因,我的toCheck變量的值正在被擦除,我不知道爲什麼。有什麼建議麼?爲什麼我的字符串失去了它的價值?
bool
check(string toCheck){
printf("toCheck: %s\n", toCheck.c_str());
ifstream list;
list.open("list.txt");
string temp;
while(list){
getline(list,temp);
printf("toCheck: '%s' temp: '%s'\n",toCheck.c_str(), temp.c_str());
if(temp == toCheck){
printf("Username exists\n");
return false;
}
}
printf("returning true\n");
return true;
}
這就是它被傳遞:TestTrevor
而這裏的輸出:
toCheck: TestTrevor toCheck: '' temp: 'Trevor' toCheck: '' temp: '' Username exists
list.txt的內容是什麼? – JohnFx 2012-04-23 23:21:21
你必須通過「list.txt」引導一些黑暗魔法。 – ScarletAmaranth 2012-04-23 23:22:21
刪除list.txt,並且只是在某些虛擬值中使用了temp,您的代碼在我的MacbookPro上可以正常工作。 – Alan 2012-04-23 23:26:48