新建空项目,之后在loginUser.cpp文件中写入这些代码
把需要放的音乐放在当前项目目录下面
成功运行:
进度条走完之后
#include<iostream>
#include<conio.h>
#include<string>
#include<regex>
#include<Windows.h>
#include<mmsystem.h>
#pragma comment(lib,"winmm.lib")
using namespace std;
void setWindowStyle() {
//调整窗口格式 标题 颜色 大小
system("title 邮箱验证");
system("color f0");
system("mode con cols=50 lines=10");
}
bool CheckEmai(char* userName) {
regex object("(\\w+)@(\\w+)(\\.(\\w+))+");
//邮箱组成:字母 a-z A-Z 或者是数字0-9或者下划线
bool result = regex_match(userName, object);
return result;
}
void proc() {
string str("■");
for (int i = 0; i <= 20; i++) {
system("cls");
cout << str << endl;
cout << i * 5 << "%" << endl;
str += "■";
Sleep(500);
}
}
int main() {
setWindowStyle();
char username[20] = "";
char password[7] = "";
cout << "\t用户名:";
cin >> username;
cout << "\t密码:";
//密码不可见处理
//每次按键输出一个*就可以,然后把所有按键保存到password里面
char key;
int i = 0;
while ((key = _getch()) != '\r') {
if (i < 6) {
password[i++] = key;
putchar('*');
}
else {
cout << "密码过长"<<endl;
system("pause");
return 0;
}
}
//字符串结束标志
password[i] = '\0';
cout << endl;
if (CheckEmai(username)) {
if (!strcmp(username, "[email protected]") && !strcmp(password, "123456")) {
//弹出进度条
proc();
cout << "begin music" << endl;
//再播放音乐
mciSendString(L"open music1.mp3 alias music",0, 0,0);
mciSendString(L"play music repeat", 0, 0, 0);
}
else {
cout << "用户名或者密码错误" << endl;
}
}
else {
cout << username<< "不是邮箱";
}
system("pause");
return 0;
}