回复 9楼 mmmmmmmmmmmm
#include<iostream>#include<vector>
#include<string>
using namespace std;
struct information
{
string name;
int number;
string address;
};
int main()
{
cout<<"◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆"<<endl;
cout<<"◆ ◆"<<endl;
cout<<"◆ § 简易通讯录 § ◆"<<endl;
cout<<"◆ ◆"<<endl;
cout<<"◆ ◆"<<endl;
cout<<"◆ 1.输入联系人信息 ☆ * $$ * ◆"<<endl;
cout<<"◆ $◢◣$ ◆"<<endl;
cout<<"◆ 2.查找联系人 ☆ * $◢★◣$ * ◆"<<endl;
cout<<"◆ $◢■■◣$ ◆"<<endl;
cout<<"◆ 3.修改联系人信息 ☆ $◢■■■◣$ ◆"<<endl;
cout<<"◆ * ︸︸||︸︸ * ◆"<<endl;
cout<<"◆ 4.显示所有联系人 ☆ || ◆"<<endl;
cout<<"◆ * * ◆"<<endl;
cout<<"◆ 5.退出 ☆ ◆"<<endl;
cout<<"◆ °☆ .★°∴ ★. ☆ ° ◆"<<endl;
cout<<"◆ ◆"<<endl;
cout<<"◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆"<<endl;
vector<information>aa;
information temp;
int n;
cout<<"please input the amount of pepole"<<endl;
cin>>n;
while(true)
{
int choice;
cout<<"please choose 1~5"<<endl;
cout<<" 1.输入联系人信息"<<endl;
cout<<" 2.查找联系人"<<endl;
cout<<" 3.修改联系人信息"<<endl;
cout<<" 4.显示所有联系人"<<endl;
cout<<" 5.退出"<<endl;
while(true)
{
cin>>choice;
if(choice<1||choice>5)
cout<<"input error,please input again"<<endl;
else
break;
}
switch(choice)
{
case 1:
{
for(int i=0;i!=n;++i)
{
cout<<"Please input name number address"<<endl;
cin>>temp.name>>temp.number>>temp.address;
aa.push_back(temp);
}
}
break;
case 2:
{
cout<<"please input name you want to look for"<<endl;
string name1;
cin>>name1;
bool flag=0;
for(vector<information>::iterator k=aa.begin();k!=aa.end();++k)
{
if((*k).name==name1)
{
cout<<(*k).name<<" "<<(*k).number<<" "<<(*k).address<<endl;
flag=1;
}
}
if(!flag)
cout<<"check no such person"<<endl;
}
break;
case 3:
{
string name2,address2;
int number2;
cout<<"please input name2 that you want to revise"<<endl;
cin>>name2;
for(vector<information>::iterator f=aa.begin();f!=aa.end();++f)
{
if((*f).name==name2)
{
cout<<"Please input name number address"<<endl;
cin>>name2>>number2>>address2;
(*f).name=name2;
(*f).number=number2;
(*f).address=address2;
cout<<(*f).name<<" "<<(*f).number<<" "<<(*f).address<<endl;
}
}
}
break;
case 4:
{
string t1;
vector<information>::iterator h;
for ( h=aa.begin();h!=aa.end()-1;++h)
{
for(vector<information>::iterator f=h+1;f!=aa.end();++f)
{
if((*h).name>(*f).name)
{
t1=(*h).name;
(*h).name=(*f).name;
(*f).name=t1;
}
}
}
for ( h=aa.begin();h!=aa.end();++h)
cout<<(*h).name<<" "<<(*h).number<<" "<<(*h).address<<endl;
}
break;
case 5:
cout<<"Goodbye!!!!"<<endl;
break;
}
}
return 0;
}
用这个吧,比较简单易懂