problem with std::cin

Jul 1, 2016 at 4:45pm
hi, I'm new in this forum. I'm doing a little program that print on the screen a life bar(with ascii code) and name of 4 moves that user can choose.
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
  switch(stato){
	case 0:
	         while(!stato) {
				    
			printLifeBar();
			std::cout << "[1]" << move1 << std::endl;
		        std::cout << "[2]" << move2 << std::endl;
			std::cout << "[3]" << move3 << std::endl;
			std::cout << "[4]" << move4 << std::endl;
                        std::cin >> stato;
			system("clear");

			}
			break;

			case 1:
				move_msg.data = stato;
				stato = 0;

			break;

			case 2:
				move_msg.data = stato;
				stato = 0;
			break;

			case 3:
				move_msg.data = stato;
				stato = 0;
			break;

			case 4:
				move_msg.data = stato;
				stato = 0;
			break;

			default:
			stato = 0;
		}

All this code is put in a special loop(I'm program on raspberry pi with ros). The program is in loop while i don't kill it in a shell.
The program wait the input from user, but i need that the program continue to clear the screen and print another time because the life bar can change its value. Only when user press a number i need to read it. Have you got any idea? thanks :)
Last edited on Jul 1, 2016 at 4:50pm
Jul 2, 2016 at 12:07am
closed account (48T7M4Gy)
Sounds like system("cls") or similar might clear the screen and you need to investigate keyboard and timer interrupts to open or wake up the menu.
Jul 2, 2016 at 7:06am
I use ubuntu so system("clear") work, the problem is: how can i do the interrupt from keyboard?
Jul 2, 2016 at 7:21am
closed account (48T7M4Gy)
http://lmgtfy.com/?q=c%2B%2B+ubuntu+keyboard+interrupt
Topic archived. No new replies allowed.