首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

c++ 通讯录 排序不会写啊该怎么解决

2012-10-21 
c++ 通讯录 排序不会写啊#include iostream#include string#include fstreamusing namespace stdcl

c++ 通讯录 排序不会写啊
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
class fox
{
public:
  void input();//添加联系人
  void shanchu();//删除联系人
  void xiugai();//修改信息
  void chaxun();//查询联系人
void paixu();//排序联系人
void help();//帮助
  void baocun();//保存新增加的联系人
char menu();
private:
  int num; //编号
char group[16]; //分组
char name[16]; //姓名
char hphone[16]; //固话home_phone 
char mphone[16]; //手机号mobile_phone 
char qq[16]; //QQ号码 
char email[20]; //e-mail地址 
int len; //家庭住址或通信地址长度
string addr; //家庭住址或通信地址

};

//添加联系人
void fox::input()
{
   
cout<<"添加联系人"<<endl;
cout<<"编号"<<endl;
cin>>num;
cout<<"分组"<<endl;
cin>>group;
cout<<"姓名"<<endl;
cin>>name;
cout<<"固话homephone"<<endl;
cin>>hphone;
cout<<"手机号mobilephone "<<endl;
cin>>mphone;
cout<<"QQ号码"<<endl;
cin>>qq;
cout<<"e-mail地址 "<<endl;
cin>>email; 
cout<<"通信地址长度"<<endl;
cin>>len;
cout<<"家庭住址"<<endl;
cin>>addr;
baocun();
cout <<endl <<endl <<"联系人信息已经保存好" <<endl <<endl;
system("pause");


}
//删除联系人
void fox::shanchu()
{

  ofstream outData("temp.txt", ios::out);
ifstream inData("pfox.txt", ios::in); 
   
if (!outData||!inData)
  {
  cout <<endl <<"没有找到文件" <<endl;
  system("pause");
  return;
  }
   
  string mark;
  cout <<endl <<"你要删除输入姓名或qq :";
  cin >>mark;
  string str1;
  bool flag = true;
  string str;
  while (inData >>name >>qq)
  {
  getline(inData, str);
   
  if ((mark==name) || (mark==qq))
  {
  cout <<endl <<"你想删除的联系人编号或qq:" <<endl <<endl;
  cout <<str1 <<endl;
  cout <<num<<" " <<qq <<str <<endl;

  flag = false;
  break;
  }
   
  outData <<num<<" " <<qq <<str <<endl;

  }
   
  if (flag)
  {
  cout <<endl <<"联系人中没你找的人" <<endl <<endl;
  }
  else
  {
  while (getline(inData, str))
  {
  outData <<str <<endl;
  }
   
  outData.close();
  inData.close();
   
  ofstream out("pfox.txt", ios::out);
  ifstream in("temp.txt", ios::in);
   
  if (!out || !in)
  {
  cout <<endl <<"不能打开文件" <<endl <<endl;
  system("cls");
  return;
  }
   


  while (getline(in, str))
  {
  out <<str <<endl;
  }
   
  out.close();
  in.close();
  cout <<endl <<"信息已经从通迅录中删除" <<endl <<endl;
  }
   
  system("pause");  

}
void fox::paixu()//排序联系人

ofstream outData("temp.txt", ios::out);
  ifstream inData("pfox.txt", ios::in); 
if (!outData || !inData)
  {
  cout <<endl <<"找不到文件" <<endl;
  system("pause");
  return;
  }








} 这个排序联系人怎么写啊

[解决办法]
都用C++了,那你可以直接用stl中的排序函数了,参考:
http://www.cplusplus.com/reference/algorithm/sort/

很easy的。
[解决办法]
把信息读到文件,再排序?不好弄。。。为什么不把联系人的所有信息都做成结构体,然后用容器排序呢?
[解决办法]
用map吧,map是字典排序

热点排行
Bad Request.