I have a lot of code right now but I did it wrong...I need to be able to put the phone number in and the name is output. I have it reversed I think but when I try to change it I get build errors. This is what I have
I'm confused as to how I alter the "cin" under Enter Phone Number and the cout where it says Number is. I know I should change it to Name is but I don't know what to put after that to make it so that when I enter the phone number it outputs the name.
A std::map is an STL data type that holds associates two values by having a value and a key to that value. In other words, you could store the name as the value and use the phone number as the key (or vice versa). Here is an example:
1 2 3 4 5 6 7 8
// Create an empty std::map with a string type key and string type value.
map<string, string> phone_book;
// Store the value "Tom Smith" behind the key "555-3322"
phone_book["555-3322"] = "Tom Smith";
// Now I can simply do this to print the name behind the number.
cout << phone_book["555-3322"] << endl;
The output would look like this.
Tom Smith
Now, I say all of this assuming that you're allowed to use whatever you wish. If this is a homework assignment and you are only allowed to use character arrays then that's a different story.