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

Computer builds, hardware and software discussion or troubleshooting, including peripherals. Essentially a general place to talk about desktop computers.
Locked
Anonymous

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

Post 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
User avatar
Red Squirrel
Posts: 29209
Joined: Wed Dec 18, 2002 12:14 am
Location: Northern Ontario
Contact:

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

Post 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
Honk if you love Jesus, text if you want to meet Him!
Locked