one some console program you have to enter any option, like a number or y,n and its enclosed in [ ] how is it done?????
Thanks
Printable View
one some console program you have to enter any option, like a number or y,n and its enclosed in [ ] how is it done?????
Thanks
On a Unix system, just print out a couple of backspace characters (\b) to move the cursor back.
I still haven't worked out how to get cin to return a single character yet though :p
what about something like this
cin.getline(String, 1, *);
Nope, can't use wildcards with that.
I think it needs to go down to the streambuf level :) Will take a look when I have some time.
char t;
cin.read(1, &t);
Might have to swap the parameters, I dont remember =).
Z.
Tried it. It still needs you to hit return afterwards.
Oh, you mean realtime input. =)
Z.
You can probably use getchar() or some other function to know when a key is pressed and then you can check the keyboard buffer to know what key was pressed. Since I haven't programmed for a couple of months, I forgot how to do this...
I believe that getchar() returns the character i gets as input, so you just assign it like this:Quote:
Originally posted by abdul
You can probably use getchar() or some other function to know when a key is pressed and then you can check the keyboard buffer to know what key was pressed. Since I haven't programmed for a couple of months, I forgot how to do this...
character = getchar();
Not sure on what arguments you'd need, but you could basically make a loop that gets the char, checks if it's [, then goes on checking each char in the string. I've done this before, it's really simple. I'll try and dig up the code.
i had to make something to trap keys for school, it doesn't wait for input, if thats what you're looking for...it uses a thread and then runs getch() :cool: