Map!

I am trying to access the first key and value stored in my name_to_email. However, an "Segmentation fault (core dumped)" error message is showing up. Any suggestions on how to do this?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <map>
using namespace std; 

/*Implement a small address book program that allows users to enter names and email addresses, remove or change entries, 
and list the entries in their address book. don't worry about saving the address book to disk; it's ok to lose the data 
when the program exits*/

int main () 
{
	string name;
	string email_address;  
	map <string, string> name_to_email; 
	map <string, string> :: iterator itr = name_to_email.begin (); 
	itr = name_to_email.begin (); 
	cout << "Enter name: "; 
	cin >> name; 
	name_to_email[name]; 
	cout << "Enter " << name << "'s " << "email address: "; 
	cin >> email_address; 
	name_to_email[name] = email_address; 
	cout << itr->first; 

	return 0; 
}
On line 15 the map is empty so begin() will return the same as end().
@Peter87

Ahhhhhh. Got it. Thank you so much!
Topic archived. No new replies allowed.