touche clavier backspace s'affiche dans std::cin
Bonjour, j'ai un léger soucis dans mon petit.
la frappe sur la touche retour arrière n'efface pas le dernier caractère tapé sur le clavier mais est affiché à la place.
y a t'il une solution simple . je poste le code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| #include <iostream>
#include <ctime>
#include <cstdlib>
#include <string>
std::string melangerlettres(std::string mot)
{
std::string melange;
int position(0);
while (mot.size() != 0)
{
position = rand() % mot.size();
melange += mot[position];
mot.erase(position, 1);
}
return melange;
}
int main()
{
std::string motMystere, motMelange, motUtilisateur, reponseRejouer;
srand(time(0));
do
{
std::system("clear");
std::cout << "mot mystere: " << std::endl;
std::cin >> motMystere;
std::system("clear");
int nombreCoups = motMystere.size();
motMelange = melangerlettres(motMystere);
do
{
std::cout << "nombre restant d'essais : " << nombreCoups << std::endl;
std::cout << "\nQuel est ce mot : " << motMelange << std::endl
<< std::endl;
std::cin >> motUtilisateur;
std::system("clear");
nombreCoups -= 1;
if (nombreCoups < 1)
{
std::cout << "PERDU, trop tard." << std::endl;
motUtilisateur = motMystere;
}
else
{
if (motUtilisateur != motMystere)
{
std::cout << "PERDU, recommence." << std::endl;
}
else
{
std::cout << "BRAVO, tu as trouvé." << std::endl;
}
}
} while (motUtilisateur != motMystere);
std::cout << "\nVoulez-vous rejouer ? (o/n)" << std::endl;
std::cin >> reponseRejouer;
} while (reponseRejouer == "o");
return 0;
} |
merci