LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   just a little question about c++ (https://www.linuxquestions.org/questions/programming-9/just-a-little-question-about-c-85987/)

Patchorus 08-26-2003 03:23 PM

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:

jmawebb 08-26-2003 08:09 PM

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

UltimaGuy 08-27-2003 06:20 AM

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...

Patchorus 08-27-2003 08:34 AM

thanks. ill test it right away:)


All times are GMT -5. The time now is 02:24 AM.