-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue
42 lines (33 loc) · 901 Bytes
/
queue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <queue>
using namespace std;
int main()
{
// Declare a queue of char
queue<char> keyQueue;
// Loop until the user presses ESC
while (true)
{
// Check if a key has been pressed
if (kbhit())
{
// Read the key and add it to the queue
char key = getch();
keyQueue.push(key);
// If the key is ESC, break the loop
if (key == 27)
break;
}
// Check if the queue is not empty
if (!keyQueue.empty())
{
// Get the first element of the queue
char key = keyQueue.front();
// Process the key
cout << "You pressed: " << key << endl;
// Remove the key from the queue
keyQueue.pop();
}
}
return 0;
}