这是C++实现的第一个简单小项目
实现功能实现账号的注册与登陆,同时将账号的信息(包括密码)保存成txt文件。
Code#include效果#include #include using namespace std; bool IsLoggedIn(){ string username, password, un, pw; cout << "Enter username: "; cin >> username; cout << "Enter password: "; cin >> password; ifstream read("data\" + username + ".txt"); getline(read, un); getline(read, pw); if(un == username && pw == password){ return true; } else return false; } int main(){ int choice; cout << "1: Registern2: LoginnYour choice: "; cin >> choice; if(choice == 1){ string username, password; cout << "select a username: " ; cin >> username; cout << "select a password: " ; cin >> password; ofstream file; file.open("data\" + username + ".txt"); file << username << endl << password; file.close(); main(); } else if(choice == 2){ bool status = IsLoggedIn(); if(!status){ cout << "False Login!" << endl; system("PAUSE"); return 0; } else{ cout << "Succesfully Logined in!" << endl; system("PAUSE"); return 1; } } }



