我正在用C ++制作一个注册和登录程序,但是当我运行该程序并输入是否要登录或注册时,它不会输出任何内容,并且不会出现任何错误。我也是一个初学者,我正在使用Visual Studio代码。
#include <iostream>
#include <fstream>
using namespace std;
// variables
char lor;
string userName;
string userPassword;
string userPassword2;
创建帐户并将其存储在创建的文件中的功能
// functions to create account
void createAcc(){
cout << "Enter your user name: " << endl;
cin >> userName;
cout << "Enter Password: " << endl;
cin >> userPassword;
cout << "Confirm Password: \n";
cin >> userPassword2;
// creating file to store the data of the user
if (userPassword == userPassword2){
ofstream userfile ("userdata.bin");
if (userfile.is_open())
{
userfile << userName << userPassword;
userfile.close();
}
else
{
cout << " ";
}
}
}
将您登录到帐户的功能
// login function
void loginAcc()
{
cout << "Enter username: " << endl;
cin >> userName;
cout << "Enter password: " << endl;
cin >> userPassword;
}
主要功能。
int main(){
// switch statement where you chose if you want to log in or create an account
switch (lor)
{
case '1':
createAcc();
break;
case '2':
loginAcc();
break;
}
cout << "If you want to create an account press 1" << endl;
cout << "If you want log in press 2" << endl;
cin >> lor;
}