I have a C++ program, where I want to read 2 values until a specific character key is pressed - in this case '0'. I would like to ask how can I accomplish that in C++ without complicating the program too much? Thanks in advance.
Pseudocode:
#include <iostream>
using namespace std;
int a,b;
int main(){
while ('0' is not pressed) {
cin>>a>>b;
}
}
如果您在 Windows 上,您可以执行if (GetAsyncKeyState(VK_A) && GetAsyncKeyState(VK_B)) { //run subroutine }
作为捕获键盘输入的一种快速简便的方法。
You may try something like this:
while(1)
{
cin>>a;
if(a != 0) cin>>b;
else break;
if(b == 0) break;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.