求教通讯录管理系统怎么把输入的数据保存到记事本里面
程序代码:
#include<iostream> #include<vector> #include<string> using namespace std; void save(); FILE *fp; void save() { char name[20]="aaa"; int num=1; fp=fopen("a.txt","w+"); fprintf(fp,"%s %d %s %s %s %s %d",temp.name,temp.number,temp.address,temp.danwei,temp.mail,temp.type,temp.QQ); fclose(fp); } struct information { string name; string number; string address; string danwei; string mail; string type; string QQ; }; int main() { printf("\n"); printf("\t\t\t **********通讯录*********\n"); printf("\t\t\t *1.输入联系人信息 *\n"); printf("\t\t\t *2.查找联系人 *\n"); printf("\t\t\t *3.修改联系人信息 *\n"); printf("\t\t\t *4.按首字母排序 *\n"); printf("\t\t\t *5.退出 *\n"); printf("\t\t\t *************************\n"); printf("\n"); vector<information>aa; information temp; int n; cout<<"请输入要添加的人数:"<<endl; cin>>n; while(true) { int choice; cout<<"\t\t\t 1.输入联系人信息\t\t\t"<<endl; cout<<"\t\t\t 2.查找联系人\t\t\t"<<endl; cout<<"\t\t\t 3.修改联系人信息\t\t\t"<<endl; cout<<"\t\t\t 4.显示所有联系人\t\t\t"<<endl; cout<<"\t\t\t 5.退出\t\t\t"<<endl; while(true) { cin>>choice; if(choice<1||choice>5) cout<<"输入错误,继续输入"<<endl; else break; } switch(choice) { case 1://输入联系人 { for(int i=0;i!=n;++i) { cout<<"请输入名字,电话号码,家庭住址,单位,分类,E-mail,QQ"<<endl; cin>>temp.name>>temp.number>>temp.address>>temp.danwei>>temp.type>>temp.mail>>temp.QQ; aa.push_back(temp); } } break; case 2: { cout<<"请输入你想查询的名字"<<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<<" "<<(*k).danwei<<" "<<(*k).mail<<" "<<(*k).QQ<<endl; flag=1; } } if(!flag) cout<<"查无此人"<<endl; } break; case 3://修改联系人 { string name2,address2,danwei2,mail2,number2,type2,QQ2; cout<<"请输入你想要修改的名字"<<endl; cin>>name2; for(vector<information>::iterator f=aa.begin();f!=aa.end();++f) { if((*f).name==name2) { cout<<"请输入名字,电话号码,家庭住址,单位,分类,E-mail,QQ"<<endl; cin>>name2>>number2>>address2>>danwei2>>type2>>mail2>>QQ2; (*f).name=name2; (*f).number=number2; (*f).address=address2; (*f).danwei=danwei2; (*f).type=type2; (*f).mail=mail2; (*f).QQ=QQ2; cout<<(*f).name<<" "<<(*f).number<<" "<<(*f).address<<" "<<(*f).danwei<<" "<<(*f).type<<" "<<(*f).mail<<" "<<(*f).QQ<<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<<" "<<(*h).danwei<<" "<<(*h).type<<" "<<(*h).mail<<" "<<(*h).QQ<<endl; } break; case 5://关闭 cout<<"bye bye!!!"<<endl; exit(0); break; } } return 0; }