我正在尝试在cpp中创建一个登录和注册程序,但是它不输出任何内容

时间:2019-10-19 10:33:55

标签: c++

我正在用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;


}

0 个答案:

没有答案