}
else
cleFlag = 0;
}
else
cleFlag = 0;
return cleFlag;
}
-----------------------------------------------------main.cpp-----------------------------------------------// C++XMLContacter.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "XMLFunction.h"
#include
#include
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
//在num.txt文件中获取目前通讯录中已有(i-1)联系人加入,当删除时不计(不会减一)
//用一个字符串加上i表示xml元素名,表示第几个联系人
int i;
char *direct = "contacter.xml";
ifstream file_in1("num.txt",ios::in);
char c;
file_in1.get(c);
file_in1.close();
i = (int)(c-'0');
Element myElement;
Element getMyElem;
cout<<"请输入自己的名字:";
cin>>myElement.elemAttri.attriName;
cout<<"请输入自己的电话号码:";
cin>>myElement.elemAttri.attriValue;
strcpy_s(myElement.elemName,"MyContacter");
getMyElem = getMyInfo(direct);
if(strcmp(getMyElem.elemAttri.attriName,"unname")
&&strcmp(getMyElem.elemAttri.attriName,myElement.elemAttri.attriName))
{
cout<<"自己名字输入错误!"<
return 0;
}
//strcpy_s(myElement.elemText,"0");
cout<<"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"<
cin>>cmd;
while(1)
{
if(cmd=='C'||cmd=='c')
{
char cmd1;
cout<<"是否确定要创建文件contacter.xml,如果创建并此文件存在里面原来的内容将清空!(Y/N)"<
if(cmd1=='Y'||cmd1=='y')
{
//如果是重新创建通讯录则需要重新复制i为,表示当前文件中有0个联系人
i = 1;
create_xml(direct,myElement);
Element friElement;
while(1)
{
cout<<"*********************************************"<
if(!strcmp(friElement.elemAttri.attriName,"0"))
break;
cout<<"请输入他(她)的电话号码:";
cin>>friElement.elemAttri.attriValue;
cout<<"属性为:";
cin>>friElement.elemText;;
strcpy_s(friElement.elemName, "contacter");
int len = strlen(friElement.elemName);
//在后面追加序号i,表示第几个联系人
friElement.elemName[len] = (char)(i+'0');
friElement.elemName[len+1] ='\0';
int creflag = insertSubElement(direct,friElement);;
if(creflag)
{
cout<<"插入联系人成功!"<
}
else
cout<<"插入联系人失败!"<
}
}
else if(cmd=='P'||cmd=='p')
{
bool priflag = printAllContacter(direct);
if(priflag)
cout<<"打印联系人成功!"<
cout<<"打印联系人失败!"<
else if(cmd=='S'||cmd=='s')
{
cout<<"请输入您要查询的联系人的名字:";
char seaName[MAX];
cin>>seaName;
Element getElem= searchSubElement(direct,seaName);
if(!strcmp(getElem.elemAttri.attriName,"0"))
cout<<"通讯录中没有此联系人!"<
{
cout<<"此联系人信息如下:"<
else
cout<<"查询失败!"<
else if(cmd=='I'||cmd=='i')
{
Element newFriElement;
bool insflag;
while(1)
{
cout<<"*********************************************"<
if(!strcmp(newFriElement.elemAttri.attriName,"0"))
break;
cout<<"请输入他(她)的电话号码:";
cin>>newFriElement.elemAttri.attriValue;
cout<<"属性为:";
cin>>newFriElement.elemText;
strcpy_s(newFriElement.elemName ,"contacter");
int len = strlen(newFriElement.elemName);
//在后面追加序号i,表示第几个联系人
newFriElement.elemName[len] = (char)(i+'0');
newFriElement.elemName[len+1] ='\0';
insflag = insertSubElement(direct,newFriElement);
if(insflag)
{
cout<<"新增联系人成功!"<
}
else
cout<<"新增联系人失败!"<
}
else if(cmd=='R'||cmd=='r')
{
cout<<"请输入你要删除的联系人的名字:"<
cin>>removeName;
char cmd2;
cout<<"您确定要删除吗?(Y/N)"<
if(cmd2=='Y'||cmd2=='y')
{
int remflag;
remflag = removeSubElement(direct,removeName);
if(remflag==1)
cout<<"删除此联系人成功!"<