Explanation:
- Include Headers:
#include <iostream>
: For input and output operations.#include <fstream>
: For file operations.#include <string>
: For string manipulations.#include <map>
: For using thestd::map
container to store account-password pairs.
- Functions:
addPassword
: Prompts the user to enter an account name and password, then stores these in thepasswords
map.viewPasswords
: Displays all stored account-password pairs. If no passwords are stored, it informs the user.savePasswords
: Saves the account-password pairs from thepasswords
map to a text file namedpasswords.txt
.loadPasswords
: Loads account-password pairs frompasswords.txt
into thepasswords
map. This allows the program to persist passwords between runs.
- Main Function:
- Load Passwords: Calls
loadPasswords
to populate thepasswords
map from the file at the start. - Menu Loop: Displays a menu for the user to choose between adding passwords, viewing passwords, or saving and exiting.
- Choice Handling: Uses a
switch
statement to handle user choices. Calls appropriate functions based on user input.
- Load Passwords: Calls
- File Format:
- Passwords are saved in a text file with each account and its corresponding password on separate lines. This format is simple and easy to read/write, but not secure. For better security, consider using encryption.
Compilation and Execution:
Compile the Program:
Run the Program: