我正在嘗試在帶有 do-while 回圈的情況下創建一個 while (true) 回圈,但是當我將 while (true) 放在情況下,選單不會回圈回控制臺,我需要關閉除錯器并再次運行它可以幫助我我是 C 新手。
這是我的代碼:
do
{
std::cout << "[0] Quit\n"; // This is Option 0 of the Menu
std::cout << "[1] Infinite Health\n"; // This is Option 1 of the Menu
std::cout << "[2] Infinite Ammo\n"; // This is Option 2 of the Menu
std::cout << "[3] Infinite Rounds\n"; // This is Option 3 of the Menu
std::cin >> choice;
switch (choice) // This is to detect the Choice the User selected
{
case 0:
std::cout << "Why did you even open me to not use me :(\n";
return 0;
case 1:
std::cout << "You Have Activated Infinite Health!\n";
while (true)
{
int health = 1000;
WriteProcessMemory(phandle, (LPVOID*)(healthPtrAddr), &health, 4, 0);
}
break;
case 2:
std::cout << "You Have Activated Infinite Ammo On Primary Weapon!\n";
while (true)
{
int ammo = 500;
WriteProcessMemory(phandle, (LPVOID*)(ammoPtrAddr), &ammo, 4, 0);
}
break;
case 3:
std::cout << "You Have Activated Infinite Rounds On Primary Weapon!";
while (true)
{
int rounds = 200;
WriteProcessMemory(phandle, (LPVOID*)(roundsPtrAddr), &rounds, 4, 0);
}
break;
}
}
while (choice !=0);
uj5u.com熱心網友回復:
是的,它不會回傳,因為它阻止了程式。
要解決您的問題,您可以將回圈放在另一個執行緒中。
如果您使用以下方法包含執行緒庫:
#include <thread>
然后,您必須定義應該運行的函式:
void keepHealth() {
while (true)
{
int health = 1000;
WriteProcessMemory(phandle, (LPVOID*)(healthPtrAddr), &health, 4, 0);
}
}
您現在可以在另一個執行緒中執行此函式:
std::thread task1(keepHealth);
如果你想傳遞你的句柄之類的引數,你必須將它們寫在函式頭中:
void keepHealth(void* pHandle, void* healthPtrAddress) {
while (true)
{
int health = 1000;
WriteProcessMemory(phandle, (LPVOID*)(healthPtrAddr), &health, 4, 0);
}
}
并像這樣傳遞它們:
std::thread task1(keepHealth, pHandle, healthPtrAddress);
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/421515.html
標籤:
上一篇:為什么用戶定義型別別的靜態和區域變數的合成默認建構式的行為不同?
下一篇:你如何在C 中計算自定義資料表
