我需要有关如何在 do-while 循环内的情况下进行循环的帮助
I need help on how to make a loop inside a case that it is inside a do-while loop
我试图在带有 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);
是的,它不会 return,因为它阻止了程序。
要解决您的问题,您可以将循环放在另一个线程中。
如果您使用以下方式包含线程库:
#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);
我试图在带有 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);
是的,它不会 return,因为它阻止了程序。
要解决您的问题,您可以将循环放在另一个线程中。
如果您使用以下方式包含线程库:
#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);