手机版

程序设计基础实验报告(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文档下载到电脑,方便复制、编辑、收藏和打印
×
二维码
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)