Hello! I am new to map and the following code returns a "segmentation fault (core dumped) error message. I'm not sure why. Any suggestions on where I am going wrong and how to fix it?
#include <iostream>
#include <cstdlib>
#include <map>
usingnamespace std;
/*Write a program with two options: register user and log in. Register user allows a new user to create a
login name and password. Log in allows a user to log in and access a second area, with options for "change
password" and "log out". Change password allows the user to change the password, and log out will return
the user to the original screen.*/
void make_account (map<string,string>&account, string user_name, string password)
{
account[user_name] = password;
}
int main ()
{
map<string, string>account;
map<string, string>::iterator it = account.begin ();
int option = 0;
string user_name;
string password;
cout << "Enter 1 to register user." << endl;
cout << "Enter 2 log into your account." << endl;
cout << "Enter: ";
cin >> option;
switch (option)
{
case 1:
{
cout << "Enter user name: ";
cin >> user_name;
cout << "Enter password: ";
cin >> password;
make_account (account, user_name, password);
cout << it->first;
break;
}
}
return 0;
}