just a little question about c++
i just wonder if anyone could tell me what i type in c++ so if i press a button in my program i tell it to do different stuff. for example "Q" i quit the program and if i press "s" i do something else. and so on...
have looked through some helpsites but i cant find just this part.:study: |
I don't think it's easy to do portably. Under Linux, you could use ncurses:
#include <curses.h> int main() { initscr(); cbreak(); noecho(); printw("Test: Hit a key.\n"); char x = getch(); printw("You pressed '%c'.\nHit another key.\n", x); getch(); endwin(); } Compile with: g++ -otest test.cc -lcurses -- Jamie Webb |
Well , you can also just get the input as a char and compare it using case statements and then execute the results.
For example, char ch; printf("Enter the char :"); scanf("%c",&ch);// ( I generally use C++ & am not sure if this correct) switch(ch): case c: // Do something case q: // Quit default: exit(0); I think this is just a sample and you have to develop from here. And I hope that this is what you have been looking for... |
thanks. ill test it right away:)
|
All times are GMT -5. The time now is 02:24 AM. |