Cannot key in more than 10 chars.

I am looking for a method to ensure that a user doesn't go over the limit of 10 characters entered into a string.

This is for a username / password scenario.

I am getting each character using _getch(); and masking the password with "*"s.

Is there a way to ensure as they are typing they don't go over 10 characters or would it have to be stored in the string and then tested?


Just looking for some guidance and a point in the right direction.


Thanks.
Maybe I'm misunderstanding what you're doing....

1
2
3
4
5
6
7
8
string userinput;

// -- get userinput from the user here, however you're doing it --

if(userinput.length() > 10)
{
  // -- give an error to the user --
}
That will do exactly what i need.

Wasn't aware of the .length function.

Thanks a lot.
Topic archived. No new replies allowed.