Here you go. Sorry if it's too long and thanks for taking the time to help.
Code:
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
#define GameNo_String "<GameNo"
#define TurnNo_String "<TurnNo"
#define NationNo_String "<NationNo"
#define Name_String "<Name"
#define Artifact_string "<Artifact"
#define Char_End_string "</Character"
#define NUM_OF_ARTIFACTS 6
#define NUM_OF_CHARS 21
typedef struct
{
int id, location;
}ARTIFACTS;
typedef struct
{
string name;
int location;
ARTIFACTS arti_list[NUM_OF_ARTIFACTS];
}CHARACTER;
int StringToInt(const string &s)
{
int i;
istringstream myStream(s);
if (myStream>>i)
return i;
else
return 0;
}
int compare_string(string str1, string str2)
{
if (str1 == str2)
return 1;
else
return 0;
}
int get_info(ifstream &finput,string str, int &i)
{
getline(finput,str,'<');
i++;
return StringToInt(str);
}
int main(int argc, char *argv[])
{
ifstream fin;
ofstream fout;
string szLine = "";
int game_num = 0, turn_num = 0, nation_num = 0, compare_string_choice = 0;
CHARACTER char_list[NUM_OF_CHARS];
fin.open("test.xml");
if(fin.fail())
{
cout << "ERROR\n";
return;
}
fout.open("out_test.xml");
if (fout.fail())
{
cout << "ERROR output";
return;
}
while (!fin.eof())
{
getline(fin,szLine,'>');
switch(compare_string_choice)
{
case 0:
if (compare_string(szLine,GameNo_String))
{
game_num=(get_info(fin,szLine,compare_string_choice));
cout << "Game number:- " << game_num << endl;
}
break;
case 1:
if (compare_string(szLine,TurnNo_String))
{
turn_num=(get_info(fin,szLine,compare_string_choice));
cout << "Turn number:- " << turn_num << endl;
}
break;
case 2:
if (compare_string(szLine,NationNo_String))
{
nation_num=(get_info(fin,szLine,compare_string_choice));
cout << "Nation number:- " << nation_num << endl;
}
break;
default:
break;
}
}
fout.close();
fin.close();
// cout << "The number of argc elements are " << argc << endl;
// cout << "The location of the program is " << argv[0] << endl << endl;
return 1;
}