i'd say this is too easy but i know damn well implementing networking & multithreading is going to take my fucking soul
This commit is contained in:
parent
60afa6126f
commit
348c353dac
2 changed files with 13 additions and 7 deletions
18
main.cpp
18
main.cpp
|
|
@ -14,6 +14,14 @@ void save_database(Db& database, std::string file_name) {
|
|||
db_file.close();
|
||||
}
|
||||
|
||||
void load_database(Db& database, std::string file_name) {
|
||||
std::ifstream db_file(file_name);
|
||||
std::string raw_file_text;
|
||||
db_file >> raw_file_text;
|
||||
db_file.close();
|
||||
database = nlohmann::json::parse(raw_file_text);
|
||||
}
|
||||
|
||||
void add_entry(Db& database, std::string key, std::string value) {
|
||||
database.push_back({key, value});
|
||||
}
|
||||
|
|
@ -45,6 +53,10 @@ void prompt_user(Db& database) {
|
|||
std::string file;
|
||||
std::cin >> file;
|
||||
save_database(database, file);
|
||||
} else if (mode == "load") {
|
||||
std::string file;
|
||||
std::cin >> file;
|
||||
load_database(database, file);
|
||||
} else {
|
||||
prompt_user(database);
|
||||
}
|
||||
|
|
@ -52,12 +64,6 @@ void prompt_user(Db& database) {
|
|||
|
||||
int main() {
|
||||
Db database;
|
||||
|
||||
database = {
|
||||
{ "name", "username" },
|
||||
{ "john", "unwanted_guest"},
|
||||
{ "laith", "ducc" }
|
||||
};
|
||||
|
||||
while (true) {
|
||||
for (std::vector entry: database) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue