masking input

Hello this is my Code for masking input
and the only problem is when i hit backspace it does delete a character from the string but it doesn't delete a asteriks from the screen

#include <iostream>
#include <conio.h>
#include <string>
using namespace std;

int main(){
char c;
string password;

while((c = _getch()) != 13)
{
if(c == 8)
{
password.erase(password.end() -1);
cout.put(c);
}
if(c != 8)
{
password += c;

if(c != 32)
{
cout.put('*');
}
}
if(c == 32)
{
cout.put(c);
}
}

cout << endl << password << endl;
system("pause");


}
Last edited on
this might be ugly and a hack but I inserted a backspace, then space and backspace to clear it up.
1
2
3
cout.put('\b');
cout.put(' ');
cout.put('\b');


instead of
 
cout.put(c);


Thank you that worked great
Topic archived. No new replies allowed.