给我打一段电话簿的代码
时间: 2024-06-03 17:09:29 浏览: 169
电话簿系统代码
以下是一段简单的电话簿代码,供参考:
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main() {
map<string, string> phoneBook;
phoneBook["Alice"] = "123-456-7890";
phoneBook["Bob"] = "234-567-8901";
phoneBook["Charlie"] = "345-678-9012";
string name;
cout << "Please enter a name: ";
cin >> name;
if (phoneBook.count(name)) {
cout << "Phone number: " << phoneBook[name] << endl;
} else {
cout << "Name not found in phone book." << endl;
}
return 0;
}
阅读全文