xml changer

i was board yesterday so i wrote the following program. it finds the xml file "example.xml". it finds the "tag and information" and lets you change the info between the opening and closing tags.unfortunately i have to find out how to determine the length of the tag name.Plus when i rewrite the information if isnt the same size, it messes with the code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include<iostream>
#include<fstream>
using namespace std;

int main()
{
    string tag, info;
    char ch[100],mess[100],sh;
    int size;
    fstream myfile;
    myfile.open("example.xml", ios::in | ios::out);
    cout << "Please enter tag name: ";
    cin >> tag;
    cout << "Enter current information: ";
    cin >> info;
    do{
        do{
                do{
                           myfile.get(sh);
                }while(sh != '<' && !myfile.eof());
                myfile.getline(ch,100,'>');
        }while(ch != tag && !myfile.eof());
        myfile.getline(mess,100,'<');
    }while(mess != info && !myfile.eof());
    cout << "Thinking..." << endl;
    if(myfile.eof())
       cout << "Tag and information doesn't exists!!!" << endl;
    else
        {cout << "<" << ch << ">" << mess << endl;
        cout << "Enter new information: ";
        cin >> info;
        size = myfile.tellg();
        size = size - 5;
        myfile.seekp(size);
        myfile << info;}
    myfile.close();
    system("pause");
    return 0;
}


i need help finding how to find the length of "tag" and how to change the info without it interfering with the tags.thanks...
It's a really bad idea to directly modify a file. The most common method is to load it completely to memory, do the appropriate changes, then write it back.
like how? i haven't messed with using memory yet...
Last edited on
Topic archived. No new replies allowed.