Witam, napisałem funkcję, która zamienia litery na gwiazdki tak jest jest w haśle.
Mam następujący problem, gdy naciskam backspace to wtedy pojawia się gwiazdka. Jak temu zapobiec. Powinna znikać.
EDIT, mam nowy kod.
Tylko w nim jest inny problem. Gdy naciskam bacspace to wtedy w haśle znak znika tylko gwiazdka z konsoli nie znika. :(
kod
#include <iostream>
#include <conio.h>
#include <string>
#include <windows.h>
using namespace std;
int main()
{
int i;
string kod;
string kod2 = "marcin";
char c;
const char ENTER = 13;
const char BACKSPACE = 8;
while(true)
{
kod.clear();
i = 0;
cout << "Podaj haslo: " << endl;
while(true)
{
c = getch();
if (c == ENTER) break;
if(c == BACKSPACE)
{
if(!kod.empty()) kod.erase(kod.length() - 1);
}
else
{
cout << "*";
kod.append(1, c);
}
}
cout << "\nPodane haslo: " << kod << endl;
cout << "Poprawne haslo: " << kod2 << endl;
if (kod == kod2)
{
cout << "\nHaslo jest poprawne\n";
break;
}
else cout << "\nHaslo jest bledne\n";
continue;
}
system("Pause");
return 0;
}