程序设计基础实验报告(5)

时间:2025-07-14

i--; } cout<<"Sort correctlly!\n"; }

int cmp(const void *m,const void *n) { return *(int *)m-*(int *)n; }

测试数据(输入、输出):

第2_4题

算法描述:

编写程序XMLtoTXT自动将XML文件email.xml转换为文本文件email.txt。命令行格式:XMLtoTXT email.xml email.txt。 源程序: No2_4.cpp

#include<iostream.h> #include<fstream.h> #include<string.h> #include<stdlib.h> void main() { fstream infile,outfile; infile.open("email.xml",ios::in); if(!infile) { cout<<"email.xml can't open.\n"; abort(); } outfile.open("email.txt",ios::out); if(!outfile) { cout<<"email.txt can't open.\n"; abort(); } char ch=0; int state=0; cout<<"Progressing......"<<endl; while((ch=infile.get())!=EOF) { char str[10]={0}; if(ch=='<') { for(int i(0);infile.peek()!='>';i++) { str[i]=infile.get(); } if(!strcmp(str,"from")) state=-1; if(state==-1&&!strcmp(str,"address")) state=1; if(!strcmp(str,"to")) state=-2; if(state==-2&&!strcmp(str,"address")) state=2; if(!strcmp(str,"subject")) state=3; if(!strcmp(str,"body")) state=4; if(state>0) { switch(state) { case 1:outfile<<"from:";break;

程序设计基础实验报告(5).doc 将本文的Word文档下载到电脑

精彩图片

热门精选

大家正在看

× 游客快捷下载通道(下载后可以自由复制和排版)

限时特价:7 元/份 原价:20元

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219