示例#1
0
int main(int argc, char** argv)
{
	if (argc < 2) {
		cout << "Usage:./run datafile." << endl;
		return -1;
	} 
	UserNetwork * network = new UserNetwork;
	network->CreateUsersFromFile(string(argv[1]));
 	int option;
	string uname, pass, pass1, pass2, rname, bday;
	string input = "";
	User *user = NULL;
	while (true) {
		cout << endl << endl << endl << "What do you want to do?" << endl;
		cout << "Option 1: Create a new user." << endl;
 		cout << "Option 2: Log in."  << endl;
		cout << "Option 3: Quit."  << endl; 
		cout << "Please input your selection: " << endl;
		if (!ReadInt(option) || option > 3 || option < 1) {
			cout << "Invalid option, please input again: " << endl;
			continue;
		} 
		switch (option) {
		case 1:
			cout << "Create a new user: "******"Please input your username: "******"Username already exists. Re-enter: " << endl;
				getline(cin, uname);
			}
		
			while (true){
				cout << "Set your password: "******"Confirm your password: "******"Passwords don't match. Re-enter. " << endl;
					continue;
				}
				break;
			}
			cout << "Enter your realname: " << endl;
			getline(cin, rname);
			cout << "Enter your birthday [MM/DD/YYYY] :  " << endl;
			getline(cin, bday);
			network->AddUser(uname, pass1, rname, bday);
			cout << "User " << uname << " added" << endl << endl;
			break;
		case 2:
			cout << "Enter username: "******"Username doesn't exist. Re-enter: " << endl;
				getline(cin, uname);
			}
			
			while (true){
				cout << "Enter your password: "******"Wrong password. Re-enter. " << endl;
					continue;
				}
				break;
			}
			menu(user);
			break;
		case 3:
			network->WriteUsersToFile(string(argv[1]));
			return 0;
		} 
	}
}