visual-c++ - 如何在我的 C++ 程序中删除退格键
问题描述
__input create;__
//input is the class for saving username and password
char c = getch();
while(c!='\n'&&c!='\r'&&c!='\b') /*does my while loop have to be modified to
check if the ASCII for backspace was entered*/
{
create.password += c;
system("cls");
cout << "Create an account" << endl << endl;
cout << "Email: " << endl;
cout << create.email << endl;
cout << endl << "Username: " << endl;
cout << create.name << endl;
cout << endl << "Password: " << endl;
cout << string(create.password.size(),'*');
//这些是用户名和密码的输入,它们都是字符串
c = getch();
}
//PS 我是新手,所以任何建议都会有所帮助。
解决方案
好吧,退格被认为是 achar
因为它是char
. 不是可打印的字符,而是控制字符。如果您查看 ASCII 表,您会发现它由数字表示,8
就像'a' == 97
.
因此,您可以检查c == 8
您的循环并做任何您想做的事情,例如删除密码的最后一个字符。
推荐阅读
- imgur - 设置 Imgur API:在文档的第 5 步生成访问令牌时出现错误状态 400
- reactjs - 你好!我正在尝试使用从后端收到的 json 制作图表,但我无法解析它
- python - Python pandas - 将日期和时间列加入带有时区的日期时间列
- css - 应用后如何反转关键帧
- python - Python Numpy - 为多个组聚合 numpy 数组
- javascript - 如何让我的函数使用不同的参数多次运行?
- c++ - Qt 中的“窗口系统”是什么?
- javascript - 如何根据一类嵌套元素更改父 div
- html - 如何模糊模态背后的所有内容?filter: blur(1px) 模糊包括模态在内的所有内容
- http - Gin 服务 []byte 作为文件