diff --git a/SimpleDigitalWalletSystem/file_handler.cpp b/SimpleDigitalWalletSystem/file_handler.cpp index ff9b82b..e8ffbc3 100644 --- a/SimpleDigitalWalletSystem/file_handler.cpp +++ b/SimpleDigitalWalletSystem/file_handler.cpp @@ -2,13 +2,39 @@ #include bool FileHandler::saveUserData(const std::vector& users, const std::string& filename) { + void saveUserData() { + std::ofstream file("users.txt"); + if (file.is_open()) { + for (const auto& user : users) { + file << user.username << " " << user.password << " " << user.balance << std::endl; + } + file.close(); + std::cout << "User data saved successfully." << std::endl; + } else { + std::cerr << "Error: Unable to open file for writing." << std::endl; + } +} -}; -bool FileHandler::loadUserData(std::vector& users, const std::string& filename) { +}; +bool FileHandler::loadUserData(std::vector& users, const std::string& filename) { -}; \ No newline at end of file +void loadUserData() { + std::ifstream file("users.txt"); + if (file.is_open()) { + std::string username, password; + double balance; + while (file >> username >> password >> balance) { + users.push_back({username, password, balance}); + } + file.close(); + std::cout << "User data loaded successfully." << std::endl; + } else { + std::cerr << "Error: Unable to open file for reading." << std::endl; +    } +} +};