|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 高山 于 2023-1-2 17:08 编辑
大佬们,不是道如何让在控制台中设置输入为*号?
我从网上搜了的都不符合我的代码
我的代码(请不要侵权):
- #include"allinclude.h"
- using namespace std;
- string vname;
- map <string,int> a;
- map <string,int> huser;
- map <string,string> vhuser;
- double ch,yuan;
- double zj;
- string name;
- int pass;
- char yesno='n';
- void start()
- {
- system("color 7C");
- cout<<"----------欢迎来到商家系统 V3.0----------"<<endl;
- cout<<"在使用本系统之前,您需要阅读以下几点:"<<endl;
- cout<<"1.本系统的更新请关注fishc.com.cn中高山的发帖"<<endl;
- cout<<"2.本程序是您的商家助理,但本程序没有存储功能,请不要在未记录数据前进行关闭程序"<<endl;
- cout<<"3.本程序是万能版,适用所有系统"<<endl;
- cout<<"↑以上就是本程序的信息了"<<endl;
- system("pause");
- system("cls");
- }
- void vspeak()
- {
- cout<<"在使用本程序前,务必仔细查看使用说明"<<endl;
- cout<<"程序作者:高山"<<endl;
- cout<<"发布机构:鱼C论坛"<<endl;
- cout<<"程序版本:V3.0"<<endl;
- cout<<"更新链接:高山账户"<<endl;
- system("pause");
- system("cls");
- }
- void hello()
- {
- cout<<"\n\
- @\n\
- / \\\n\
- * *\n\
- * *\n\
- * *\n\
- * * * * * *\n\
- * * * * * * * *\n\
- * * * * * * * * * *\n\
- * *\n\
- * *\n\
- * * * *\n\
- * * * * * *\n";
- cout<<"正在启动..."<<endl;
- Sleep(200);
- system("cls");
-
- }
- void clac()
- {
- system("color 2F");
- system("cls");
- char ch;
- double number=0,doing;
- cout<<"欢迎您使用计算系统,为了保证计算的快速,将使用自动读取功能,第一步时无需按下回车"<<endl;
- while(true)
- {
- cout<<"请问您要进行什么操作?"<<endl;
- cout<<"1.加法 2.减法 3.乘法 4.除法 5.结束"<<endl;
- ch=getch();
- if(ch=='1')
- {
- cout<<"请输入加的数量:";
- cin>>doing;
- number+=doing;
- cout<<"完成!"<<endl;
- system("pause");
- system("cls");
- }
- if(ch=='2')
- {
- cout<<"请输入减的数量:";
- cin>>doing;
- number-=doing;
- cout<<"完成!"<<endl;
- system("pause");
- system("cls");
- }
- if(ch=='3')
- {
- cout<<"请输入乘的数量:";
- cin>>doing;
- number*=doing;
- cout<<"完成!"<<endl;
- system("pause");
- system("cls");
- }
- if(ch=='4')
- {
- cout<<"请输入除的数量:";
- cin>>doing;
- number/=doing;
- cout<<"完成!"<<endl;
- system("pause");
- system("cls");
- }
- if(ch=='5')
- {
- cout<<"结果是"<<number<<endl;
- system("pause");
- system("cls");
- system("color 7A");
- return ;
- }
- }
- }
- void store()
- {
- system("cls");
- cout<<"欢迎来到商品管理系统"<<endl;
- cout<<"请输入商品名称:";
- cin>>name;
- cout<<"请输入商品价格:";
- cin>>yuan;
- if(yuan==0)
- {
- cout<<"价格不能为空哦~"<<endl;
- system("pause");
- system("cls");
- }
- else
- {
- a[name]=yuan;
- system("pause");
- system("cls");
- }
- }
- void vfind()
- {
- system("cls");
- cout<<"欢迎进入商品查价系统!"<<endl;
- cout<<"请输入需要查找的商品名称:";
- cin>>name;
- if(a[name]==0)
- {
- cout<<"商品不存在哦~"<<endl;
- a[name]=yuan;
- system("pause");
- system("cls");
- }
- else
- {
- cout<<"名称为 "<<name<<" 的价格为 "<<a[name]<<" 元"<<endl;
- system("pause");
- system("cls");
- }
- }
- void vdel()
- {
- system("cls");
- char choose;
- string vname;
- system("color 4F");
- cout<<"您已经进入商品删除系统,删除后无法恢复,确认操作(y/n):";
- cin>>choose;
- if(choose=='y')
- {
- cout<<"请输入需要删除的商品:";
- cin>>vname;
- if(a[vname]==0)
- {
- cout<<"删除失败!商品不存在"<<endl;
- system("pause");
- system("cls");
- system("color 7C");
- return;
- }
- a[vname]=0;
- cout<<"删除成功!"<<endl;
- system("pause");
- system("cls");
- system("color 7C");
- return;
- }
- if(choose=='n')
- {
- system("color 7C");
- return ;
- }
- }
- void yuanwrite()
- {
- system("cls");
- char choose;
- double lsyuan;
- cout<<"欢迎使用智能账本功能!"<<endl;
- while(true)
- {
- cout<<"请输入目前是收入/支出/查看价格/退出智能账本(命令为:s/z/f/e):";
- cin>>choose;
- if(choose =='s')
- {
- cout<<"请输入收入价格:" ;
- cin>>lsyuan;
- zj+=lsyuan;
- cout<<"成功!"<<endl;
- system("pause");
- system("cls");
- }
- else if(choose =='z')
- {
- cout<<"请输入支出价格:";
- cin>>lsyuan;
- zj-=lsyuan;
- if(zj<0)
- {
- cout<<"余额为负数,余额为"<<zj<<"元"<<endl;
- }
- system("pause");
- system("cls");
- }
- else if(choose=='f')
- {
- cout<<"您的余额为"<<zj<<"元"<<endl;
- system("pause");
- system("cls");
- }
- else if(choose=='e')
- {
- cout<<"感谢使用!现在返回首页"<<endl;
- system("pause");
- system("cls");
- return ;
- }
- }
-
- }
- void close()
- {
- system("color 4F");
- system("cls");
- char choose;
- cout<<"确定关闭本系统?关闭后包括账本、商品的数据都会丢失!"<<endl;
- cout<<"请问是否关闭(y/n):";
- cin>>choose;
- if(choose == 'y')
- {
- cout<<"正在操作中..."<<endl;
- system("pause");
- exit(0);
- }
- else
- {
- system("color 7C");
- return ;
- }
- }
- void word()
- {
- system("cls");
- int choose;
- string vword;
- cout<<"---------------------意见反馈内容---------------------"<<endl;
- cout<<"1.管理不当 2.发现bug 3.发展建议 4.其他反馈"<<endl;
- cout<<"请输入您的选择:";
- cin>>choose;
- if(choose==1)
- {
- cout<<"请输入具体内容,不支持多行文本:";
- cin>>vword;
- cout<<"请复制以下内容通知高山(系统不支持复制请右键点击程序标题,点击选择,复制):"<<endl;
- cout<<"意见反馈表"<<endl;
- cout<<"编号:1 类型:管理不当 版本:万能2.0"<<endl;
- cout<<"具体内容:"<<vword<<endl;
- cout<<"下面按下任意键后关闭"<<endl;
- system("pause");
- system("cls");
- return ;
- }
- if(choose==2)
- {
- cout<<"请输入具体内容,不支持多行文本:";
- cin>>vword;
- cout<<"请复制以下内容通知高山(系统不支持复制请右键点击程序标题,点击选择,复制):"<<endl;
- cout<<"意见反馈表"<<endl;
- cout<<"编号:2 类型:发现bug 版本:万能2.0"<<endl;
- cout<<"具体内容:"<<vword<<endl;
- cout<<"下面按下任意键后关闭"<<endl;
- system("pause");
- system("cls");
- return ;
- }
- if(choose==3)
- {
- cout<<"请输入具体内容,不支持多行文本:";
- cin>>vword;
- cout<<"请复制以下内容通知高山(系统不支持复制请右键点击程序标题,点击选择,复制):"<<endl;
- cout<<"意见反馈表"<<endl;
- cout<<"编号:3 类型:发展建议 版本:万能2.0"<<endl;
- cout<<"具体内容:"<<vword<<endl;
- cout<<"下面按下任意键后关闭"<<endl;
- system("pause");
- system("cls");
- return ;
- }
- if(choose==4)
- {
- cout<<"请输入具体内容,不支持多行文本:";
- cin>>vword;
- cout<<"请复制以下内容通知高山(系统不支持复制请右键点击程序标题,点击选择,复制):"<<endl;
- cout<<"意见反馈表"<<endl;
- cout<<"编号:4 类型:其他反馈 版本:万能2.0"<<endl;
- cout<<"具体内容:"<<vword<<endl;
- cout<<"下面按下任意键后关闭"<<endl;
- system("pause");
- system("cls");
- return ;
- }
- }
- void systemclose()
- {
- system("cls");
- system("color 4F");
- char choose;
- cout<<"确定关闭本电脑?关闭后包括账本、商品的数据都会丢失!"<<endl;
- cout<<"请问是否关闭(y/n),输入操作前请保存未保存的工作:";
- cin>>choose;
- if(choose == 'y')
- {
- system("pause");
- system("shutdown -s -t 10");
- }
- else
- {
- system("color 7C");
- return ;
- }
- }
- void vsay()
- {
- system("cls");
- cout<<"程序版本:万能系统版V3.0"<<endl;
- cout<<"更新日志:"<<endl;
- cout<<"-修复了部分bug"<<endl;
- cout<<"-增加了账户功能"<<endl;
- cout<<"-设置了账户的用户组"<<endl;
- cout<<"-其他关于账户的功能"<<endl;
- system("pause");
- system("cls");
- }
- void newuser()
- {
- system("cls");
- string uname;
- int upass,choose;
- cout<<"您已经进入账户管理系统"<<endl;
- cout<<"请输入想要添加的用户名(谨慎起名,目前不支持修改账户昵称):";
- cin>>name;
- cout<<"请输入 "<<name<<" 的密码(密码不能设置为0,否则无效):";
- cin>>upass;
- cout<<"请输入 "<<name<<" 的用户组"<<endl;
- cout<<"1.管理团队 2.VIP用户 3.普通用户 4.禁止访问"<<endl;
- cout<<"您的选择是:";
- cin>>choose;
- huser[name]=upass;
- if(choose==1) vhuser[name]="管理团队";
- if(choose==2) vhuser[name]="VIP用户";
- if(choose==3) vhuser[name]="普通用户";
- if(choose==4) vhuser[name]="禁止访问";
- cout<<"新建成功!"<<endl;
- system("pause");
- system("cls");
- }
-
- void vdeluser()
- {
- int yn2;
- string vname;
- system("cls");
- system("color 4F");
- cout<<"您已进入账户删除系统"<<endl;
- cout<<"是否开始删除(是选择1,不是选择2):";
- cin>>yn2;
- if(yn2==2)
- {
- system("color 7C");
- return ;
- }
- cout<<"请输入需要删除的用户名:";
- cin>>vname;
- if(huser[vname]==0)
- {
- cout<<"账户不存在!"<<endl;
- system("pause");
- system("cls");
- return ;
- }
- huser[vname]=0;
- vhuser[vname]="无效";
- cout<<"删除成功!"<<endl;
- system("pause");
- system("cls");
- system("color 7C");
- }
- void aduser()
- {
- int ch1,newpass;
- system("cls");
- string vhname,newname;
- cout<<"欢迎进入账户管理系统"<<endl;
- cout<<"请输入需要管理的账户:";
- cin>>vhname;
- if(huser[vhname]==0)
- {
- cout<<"账户不存在!"<<endl;
- system("pause");
- system("cls");
- return ;
- }
- cout<<"账户名称:"<<vhname<<endl;
- cout<<"账户密码:"<<huser[vhname]<<" 账户权限:"<<vhuser[vhname]<<endl;
- cout<<"操作:"<<endl;
- cout<<"1.修改昵称 2.修改密码 3.设为管理"<<endl;
- cout<<"4.设为特权 5.设为普通 6.禁止访问"<<endl;
- cout<<"7.不操作"<<endl;
- cout<<"请输入您的选择:";
- cin>>ch1;
- if(ch1==1)
- {
- cout<<"由于用户名混乱,本站目前不支持修改昵称!"<<endl;
- system("pause");
- system("cls");
- }
- if(ch1==2)
- {
- cout<<"请输入 "<<vhname<<" 的新密码:";
- cin>>newpass;
- huser[vhname]=newpass;
- cout<<"修改成功!"<<endl;
- system("pause");
- system("cls");
- }
- if(ch1==3)
- {
- vhuser[vhname]="管理团队";
- cout<<"设置成功!"<<endl;
- system("pause");
- system("cls");
- }
- if(ch1==4)
- {
- vhuser[vhname]="VIP用户";
- cout<<"设置成功!"<<endl;
- system("pause");
- system("cls");
- }
- if(ch1==5)
- {
- vhuser[vhname]="普通用户";
- cout<<"设置成功!"<<endl;
- system("pause");
- system("cls");
- }
- if(ch1==6)
- {
- vhuser[vhname]="禁止访问";
- cout<<"设置成功!"<<endl;
- system("pause");
- system("cls");
- }
- if(ch==7)
- {
- return ;
- }
- }
- void namewrite()
- {
- system("cls");
- cout<<"抱歉,因为用户名混乱,本站不支持任何用户名修改!"<<endl;
- system("pause");
- system("cls");
- }
-
- void passwrite()
- {
- int vnewpass;
- int hpass2;
- string vhname2;
- system("cls");
- cout<<"为了保证账户安全,您需要重新进行用户名、密码的验证"<<endl;
- cout<<"请输入您的账号:";
- cin>>vhname2;
- cout<<"请输入您的密码:";
- cin>>hpass2;
- if(huser[vhname2] != hpass2)
- {
- cout<<"账户或密码错误!"<<endl;
- system("pause");
- system("cls");
- return ;
- }
- cout<<"输入正确!请输入您的新密码:";
- cin>>vnewpass;
- huser[vhname2]=vnewpass;
- cout<<"修改成功!"<<endl;
- system("pause");
- system("cls");
- yesno='n';
- return ;
- }
- void work1()
- {
- int ch=0;
- if(yesno='y')
- {
-
- if(huser[vname] != pass )
- {
- cout<<"账号或密码错误!"<<endl;
- system("pause");
- system("cls");
- yesno ='n';
- return ;
- }
- if(vhuser[vname] == "管理团队")
- {
- yesno='y';
- ch=0;
- cout<<"欢迎您回到首页,尊敬的用户 "<<vname<<",您的用户组为 "<<vhuser[vname]<<endl;
- Sleep(1000);
- system("cls");
- cout<<"------欢迎来到商家助理 V3.0------"<<endl;
- cout<<"请选择您需要使用的功能:"<<endl;
- cout<<"1.计算功能 2.添加商品 3.商品查价"<<endl;
- cout<<"4.删除商品 5.智能账本 6.意见反馈"<<endl;
- cout<<"7.添加账户 8.删除账户 9.管理账户"<<endl;
- cout<<"10.修改昵称 11.修改密码 12.退出账户"<<endl;
- cout<<"13.升级日志 14.关闭程序 15.关闭电脑" <<endl;
- cout<<"请输入您的选择:";
- cin>>ch;
- if(ch==1) clac();
- if(ch==2) store();
- if(ch==3) vfind();
- if(ch==4) vdel();
- if(ch==5) yuanwrite();
- if(ch==6) word();
- if(ch==7) newuser();
- if(ch==8) vdeluser();
- if(ch==9) aduser();
- if(ch==10) namewrite();
- if(ch==11) passwrite();
- if(ch==13) vsay();
- if(ch==14) close();
- if(ch==15) systemclose();
- if(ch==12)//12放在最后才能退出账户
- {
- yesno='n';
- system("cls");
- return ;
- }
- }
- if(vhuser[vname] == "VIP用户")
- {
- yesno='y';
- ch=0;
- cout<<"欢迎您回到首页,尊敬的用户 "<<vname<<",您的用户组为 "<<vhuser[vname]<<endl;
- Sleep(1000);
- system("cls");
- cout<<"------欢迎来到商家助理 V3.0------"<<endl;
- cout<<"请选择您需要使用的功能:"<<endl;
- cout<<"1.计算功能 2.添加商品 3.商品查价"<<endl;
- cout<<"4.删除商品 5.智能账本 6.意见反馈"<<endl;
- cout<<"7.修改昵称 8.修改密码 9.退出账户"<<endl;
- cout<<"10.升级日志" <<endl;
- cout<<"请输入您的选择:";
- cin>>ch;
- if(ch==1) clac();
- if(ch==2) store();
- if(ch==3) vfind();
- if(ch==4) vdel();
- if(ch==5) yuanwrite();
- if(ch==6) word();
- if(ch==7) namewrite();
- if(ch==8) passwrite();
- if(ch==10) vsay();
- if(ch==9)//9放在最后才能退出账户
- {
- yesno='n';
- system("cls");
- return ;
- }
- }
- if(vhuser[vname] == "普通用户")
- {
- yesno='y';
- ch=0;
- cout<<"欢迎您回到首页,尊敬的用户 "<<vname<<",您的用户组为 "<<vhuser[vname]<<endl;
- Sleep(1000);
- system("cls");
- cout<<"------欢迎来到商家助理 V3.0------"<<endl;
- cout<<"请选择您需要使用的功能:"<<endl;
- cout<<"1.计算功能 2.添加商品 3.商品查价"<<endl;
- cout<<"4.智能账本 5.修改昵称 6.修改密码"<<endl;
- cout<<"7.退出账户 8.升级日志" <<endl;
- cout<<"请输入您的选择:";
- cin>>ch;
- if(ch==1) clac();
- if(ch==2) store();
- if(ch==3) vfind();
- if(ch==4) yuanwrite();
- if(ch==5) namewrite();
- if(ch==6) passwrite();
- if(ch==8) vsay();
- if(ch==7)//9放在最后才能退出账户
- {
- yesno='n';
- system("cls");
- return ;
- }
- }
- if(vhuser[vname] == "禁止访问")
- {
- ch=0;
- cout<<"欢迎您回来,尊敬的用户 "<<vname<<",您的用户组为 "<<vhuser[vname]<<endl;
- Sleep(1000);
- system("cls");
- cout<<"------欢迎来到商家助理 V3.0------"<<endl;
- cout<<"提醒:您的账户已被封禁"<<endl;
- cout<<"1.退出账户"<<endl;
- cin>>ch;
- if(ch==1)
- {
- cout<<"1秒后即将退出账户,感谢您的使用"<<endl;
- Sleep(1000);
- system("cls");
- yesno='n';
- return ;
- }
- }
- }
-
- }
- int main()
- {
- huser ["Admin"]=123456;
- vhuser ["Admin"]="管理团队";
- start();
- vspeak();
- hello();
- while(true)
- {
- work1();
- }
- }
复制代码
就是只在work1函数中的输入密码环节设置输入内容为“*”,后面输入完了就解除(不过不要那种按退格键或者回车键就自动加一个字符的那种)
抱歉,给大家添麻烦了
本帖最后由 人造人 于 2023-1-2 17:50 编辑
我没有找到通用的方法
这个代码不知道windows能不能用
dev-cpp的话应该能用吧
- #include <stdio.h>
- #include <termios.h>
- #include <unistd.h>
- #include <stdbool.h>
- void echo(bool enable) {
- struct termios attr;
- tcgetattr(STDOUT_FILENO, &attr);
- attr.c_lflag &= ~(ICANON | ECHO);
- if(enable) attr.c_lflag |= ICANON | ECHO;
- tcsetattr(STDOUT_FILENO, TCSANOW, &attr);
- }
- void get_passwd(char buff[], size_t size, bool display_star) {
- if(size == 0) return;
- echo(false);
- for(size_t i = 0; i < size - 1; ++i) {
- int ch = getchar();
- if(ch == '\n' || ch == EOF) break;
- *buff++ = ch;
- if(display_star) putchar('*');
- }
- *buff = '\0';
- putchar('\n');
- echo(true);
- }
- int main(void) {
- char buff[1024];
- printf("请输入密码:");
- get_passwd(buff, 1024, true);
- puts(buff);
- printf("请输入名字:");
- scanf("%s", buff);
- puts(buff);
- return 0;
- }
复制代码
|
|