c++ 在循环中如何复制给 struct的成员 最终想要的结果就是 可以在函数dealxml外 取到文件的值

小粽子er 2017-09-08 09:11:45
#include "stdafx.h"
#include <stdio.h>
#include "tinyxml.h"
#include <iostream>
#include <cstring>
#include<string>
using namespace std;
string dealxml(string n);
TiXmlDocument mydoc("aa.xml");//xml文档对象 定义全局变量mydoc
struct IMtkPb_Ctrl_SetDisplayRectangleEx
{
string a;
string b;
string c;
string d;
}IMtkPb_Ctrl_SetDisplayRectangleEx;

struct IMtkPb_Ctrl_SetEncryptInfo
{
string a;
string b;
string c;
string d;
}IMtkPb_Ctrl_SetEncryptInfo;

int main()
{
bool loadOk=mydoc.LoadFile();//加载文档
if(!loadOk)//判断是否加载成功
{
cout<<"***************没有加载成功***************"<<endl;
system("pause");
exit(1);
}
//提示输入接口2
char name[40];
cout<<"请输入接口名字:"<<endl;
cin.getline(name,40);
dealxml(name);

cout<<endl<<endl<<endl<<IMtkPb_Ctrl_SetDisplayRectangleEx.a<<endl;

system("pause");
}

/***************************读取接口*******************************/

string dealxml(string n)
{
string a[10];
const char *c = n.data();
TiXmlElement *RootElement1=mydoc.RootElement(); //根元素
//cout<< "[root name]" << RootElement1->Value() <<"\n"; //<PlayBackCase1>
for (TiXmlElement *StuElement=RootElement1->FirstChildElement();StuElement; StuElement = StuElement->NextSiblingElement())
{
if ( strcmp(StuElement->Value(),c) == 0) //判断接口名字是否一样
{
//遍历子节点
for(TiXmlElement *sonElement=StuElement->FirstChildElement(); sonElement ; sonElement=sonElement->NextSiblingElement())
{
cout <<(IMtkPb_Ctrl_SetDisplayRectangleEx.a=sonElement->Value())<<endl;
//遍历孙节点
for(TiXmlElement *grandsonElement=sonElement->FirstChildElement(); grandsonElement; grandsonElement=grandsonElement->NextSiblingElement())
{
cout<<grandsonElement->Value();

while( NULL != grandsonElement->GetText())//<u4X>0</u4X> 判断0 是否存在
{
cout<<":"<<grandsonElement->GetText()<<endl;
break;
}
//遍历重孙节点
for(TiXmlElement *ggrandsonElement=grandsonElement->FirstChildElement(); ggrandsonElement ; ggrandsonElement=ggrandsonElement->NextSiblingElement())
{
cout<<ggrandsonElement->Value()<<" : ";
while( NULL != ggrandsonElement->GetText())
{
cout<<ggrandsonElement->GetText()<<endl;
break;
}
}
}
}
}
else
{
continue;
}
}
return n;
}
...全文
1552 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此,在求职或创业过程,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

1,221

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧