@IWishIKnew
What I meant was that I think you should change this part of your code:
1 2 3 4
|
else if((ch == 0x08) && (input.size() > 0))
{
input.resize((input.size() - 1));
}
|
to this:
1 2 3 4 5
|
else if (ch == 0x08)
{
if (input.size() > 0)
input.resize((input.size() - 1));
}
|
As it is right now, if someone presses the backspace key before inputting any other letters, it gets saved to your input variable.
I used this main function to test it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
int main(void)
{
system("CLS");
string ret;
ret = opt_input("Enter something: "); /**any_string = opt_input(string message) */
system("CLS");
cout << "Returns: " << ret << endl; //what to do with the string? display it
cout << "Size is " << ret.size() << " characters.\n";
string str;
cout << "Re-enter what you typed: ";
cin >> str;
if (str == ret)
cout << "It matches the stored word.\n";
else
cout << "It doesn't match the stored word.\n";
system("PAUSE");
return 0;
}
|
If I type "password", the output is correct:
Returns: password
Size is 8 characters.
|
But if I press backspace before typing "password" then the output is like this:
Returns:password
Size is 9 characters.
|
Then if I try to type in "password" when prompted to re-type what I had, the result is:
Returns:password
Size is 9 characters.
Re-enter what you typed: password
It doesn't match the stored word.
|
While I suppose this really isn't a big deal, and it's unlikely that someone would press backspace before typing anything, it's such an easy fix I wanted to point it out.
EDIT:
Actually, now that I think about it, it is a big deal. How many of us have started typing a password, then had a typo, and deleted what we typed? And even though we only typed 5 letters or so, we press backspace 7-8 times?