搜索文件的特定位置

Search specific position of file

本文关键字:定位 位置 文件 搜索      更新时间:2023-10-16

我正在使用XMLReader,所以我想在XML文件中的标签之间阅读,但是我不知道如何读取文件中的特定位置?有建议吗?到目前为止,我要做的是:

#pragma once
#include<iostream>
#include<string>
#include<iostream>
#include<fstream>
#include<vector>
using namespace std;
class XmlReader
{
public:
    void Read(ifstream &Read, string searchWord,int args)
    {
        string line = "";
        string endline = "";
        string OptionLine = "";
        char array[100];
        bool isXml=false;
        while (!Read.eof())
        {
            string firstSearchWord = "<" + searchWord + ">";
            string endSearchWord = "</" + searchWord + ">";
            cout << line;
            if (line.find(firstSearchWord) && line.find(endSearchWord))
            {
            }
        }
    }
};

这个只是很好的标签并正确的语法,我不知道如何在它们之间阅读。我想从中读到的示例是: <Gun1>Speed=100,Power=20,Ammo=50</Gun1>

谢谢..!

通过XML搜索将其视为常规字符串不是一个好主意。XML可能包含您不会忽略的评论XML,或者可能会检查的CDATA部分。

最好的选择是使用适当的XML解析器处理XML Xerces-C 是这种事情的好候选者。