#include<iostream>
using namespace std;
#include<string>
#include<fstream>
#include <conio.h>
#include<string.h>
#include<windows.h>
typedef struct user
{
string password;
string name;
}user;
void regist()
{ //注册
char *password = new char[20];//分配20个字节,然后返回首地址给password,即password可以看做一个20字节的字符数组,即字符串
string name;
/*void regist()
2 { //注册
3 char *password = new char[20];//分配20个字节,然后返回首地址给password,即password可以看做一个20字节的字符数组,即字符串
4 string name;
5 /*struct user
6 {
7 string password;
8 string name;
9 };定义的用户结构体*/
user c;
ifstream fin;//声明 ifstream 对象
fin.open("user.txr",ios::in);//关联文件
cout << "请输入用户名:";
cin>>name;
while(fin >> c.name >> c.password)//读取成功返回1
{
if(c.name==name)
{cout << "该用户名已被注册" <<endl;regist();}
}
char test ;int i=0;
cout << "输入密码:";
while((test=getch())!='\r')
{
if(test==8)//ASC2码8为退格
{
if(i>0)
{
cout << test << " " << test;
password[i--]='\0';
}
}
else
{
if(i<20)
{
cout << "*" ;
password[i]=test;
i++;
}
}
}
password[i] = '\0';
cout << "再次输入密码" ;
char *password2 = new char[20];
i=0;
while((test=getch())!='\r')
{
if(test==8)
{
if(i>0)
{
cout << test << " " << test ;
password2[i--]='\0';
}
}
else
{
if(i<20)
{
cout << "*";
password2[i]=test;
i++;
}
}
password2[i]='\0';
}
if(strcmp(password,password2)!=0)
{
cout << "密码两次输入不正确";
regist();
}
else
{
cout << "注册成功";
}
ofstream fout;
fout.open("user.txr",ios_base::out|ios_base::app);
fout.close();//关闭文件连接,但不会删除流
cout << "三秒后返回登陆界面";
}
int main(){
regist();
return 0;
}
浙公网安备 33010602011771号