每當我鍵入命令在我的程序運行這個功能,它運行,然後崩潰說:爲什麼我的程序在運行這個特殊功能後崩潰?
「應用程序已請求運行時終止它以不同尋常的方式。」
它爲什麼這樣做?
void showInventory(player& obj) {
std::cout << "\nINVENTORY:\n";
for(int i = 0; i < 20; i++) {
std::cout << obj.getItem(i);
i++;
std::cout << "\t\t\t" << obj.getItem(i) << "\n";
}
}
std::string getItem(int i) {
return inventory[i];
}
getItem()是如何寫的?它是否直接索引數組?你跑出界限了嗎? –
這可能與'i'在每次循環迭代中增加3次這一事實有關。 – chris
您正在添加一個字符串('char *')和'obj.getItem(i)'的返回值。你可能打算使用'<<'而不是'+'。 – Schnouki