C++学习day7
思维导图:
使用vector实现一个简单的本地注册登录系统 注册:将账号密码存入vector里面,注意防重复判断 登录:判断登录的账号密码是否正确
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <unistd.h>
#include <sstream>
#include <vector>
#include <memory>
using namespace std;
struct user {
string name;
string pwd;
};
//输出
template <class T>
class myVector:public vector<T>
{
public:
myVector& operator<<(const T& val)
{
vector<T>::push_back(val);
return *this;
}
};
int main(int argc,const char** argv){
user stu;
cout << "请输入注册的账号和密码" << endl;
cin >> stu.name ;
cin >> stu.pwd ;
vector<string> v;
v.push_back(stu.name);
v.push_back(stu.pwd);
user stu1;
cout << "请输入已有的账号和密码" << endl;
cin >> stu1.name ;
cin >> stu1.pwd ;
if(v[0]==stu1.name && v[1]==stu1.pwd)
{
cout << "登录成功" << endl;
}
else
{
cout << "登录失败" << endl;
}
return 0;
}