Page 1 of 1

How can I restrict the cursor not to go furter...?

Posted: Fri Mar 17, 2006 11:27 am
by Anonymous
How can I restrict the cursor not to go further... (in c++) i.e. when I carry out the
program and the program waits for numbers or chars isertion, I want to
allow just a determined number (for instance 4) of digits or chars to be
entered. It won't allow me to enter the fifth char and will wait for ENTER. :huh:

Thank you in advance, Alexandar



Archived topic from Iceteks, old topic ID:4236, old post ID:34306

How can I restrict the cursor not to go furter...?

Posted: Fri Mar 17, 2006 12:22 pm
by Red Squirrel
Guessing your doing this with a console? What I would do is, instead of using cin>> or cin.getline, use getch(). It gets 1 character. So make a loop that keeps grabing 1 char until you got 4, or an enter.

a = getch();

would get 1 char from the user and store it in a. It wont wait for enter or anything.

There's probably better ways but this is one of them.

Archived topic from Iceteks, old topic ID:4236, old post ID:34308