#include <iostream>
#include <string>
#include <conio.h>
void Password()
{
std::cout << "Please Enter A Password: ";
std::string password;
int temp;
do
{
temp = _getch();
if (temp != 0 && temp != 13)
{
password += (char)temp;
std::cout << "*";
}
if(temp == 8)
{
password = password.substr(0, password.length()-1);
ClearScreen();
std::cout << "Please Enter A Password: ";
for(unsignedint i = 0; i < password.length(); i++)
{
std::cout << "*";
}
}
}while (temp != 13);
std::cout << "\nYour Password is: " << password << std::endl;
}
This compiles fine and works except for backspace. Which in conio.h is equal to 8. But when pressed doesn't do what I want it to. Basically to create a fake backspace to remove a character and then displays the "*" -1 as well in the console output.
ClearScreen() is my own function else where and works fine.