所以我正在编写一个用户文件创建,到目前为止我已经完成了,但我被困在如何在文本中获取特定行并在程序中使用该变量。
int Player::CheckAccount()
{
Network net;
bool fileFound = false;
string user = GetLoginUser();
string openDir = "./Characters/" + user + "/" + user + ".ini";
if (fileFound == false) {
ifstream openFile(openDir);
if (openFile.good()) {
util::Logger::Dbg("File found for user " + user);
openFile.open(openDir);
util::Logger::Dbg("User file " + user + " is ready to be checked");
fileFound = true;
} else {
util::Logger::Dbg("Could not find user file for " + user + " creating new character file" );
CreateAccount(GetLoginUser());
}
}
return net.GetFinalSize() == 1;
}
void Player::CreateAccount(string user)
{
string dir = "./Characters/" + user;
if(CreateDirectory(dir.c_str(), NULL)) {
util::Logger::Dbg("Created new user directory for " + user);
} else {
util::Logger::Dbg("Could not create new user directory for " + user);
}
string fileName = user + ".ini";
ofstream createUser;
string charDir = "./Characters/" + user + "/" + fileName;
createUser.open(charDir);
SetPlayerBanned(false);
SetInAppUsername(user);
createUser << "Username = " << GetLoginUser() << endl;
createUser << "Password = " << GetLoginPass() << endl;
createUser << "app Username = " << GetInAppUsername() << endl;
createUser << "Status = " << GetStatus() << endl;
createUser << "Bio = " << GetBio() << endl;
createUser << "Banned status = " << IsPlayerBanned() << endl;
createUser << "Avatar dir = " << GetAvatarDir() << endl;
createUser.close();
}
所以在 checkaccount 函数中,我希望能够从文本文档中提取变量,这将是一个 bool banstatus。虽然我不想做的是必须使用外部库,但我希望能够直接从 Windows 中完成。