getch() and other oddities
Hye everyone,
So check this out...I have this code, I know it doesnt do anything...it's for test purposes:
Code:
cout << "What is your name?";
char ch = getch();
while (ch != '\r')
{
if (ch >= '0' && ch <= '9')
{
cout << ch;
}
ch = getch();
}
So what this does is basically only allows the user to enter numbers...but a few questions arise...due to the restrictions of this, the ability to delete is cut off...I tried testing for ch == '\b' but that only went back a space everytime I hit delete...not exactly helpful...any creative solutions around this?...I searched online for a while and didnt find any escape sequence that would mean a delete...I was actually surprised by that.
Ok so there's that...and then there's this...so using my backspacing I was able to start overwriting the string literal "What is your name?"...so now my question is does that affect your program at all? I mean I'm not exactly sure what is happening with backspacing on top of already printed to the screen characters...so...any insight into whether only aesthetic issues arise or if I'm tapping into anything bad...I dunno...just curious...sorry if I'm not making myself clear, any help would be the *expletive deleted for the sake of all readers* :eek: -Chap