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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
//20.05.11
// read a xml File
#include <iostream>
#include <math.h>
#include <sstream>
#include <fstream>
#include <string>
using namespace std;
struct point
{
double x;
double y;
double dx;
double dy;
};
struct point p[500];
struct point q[500];
void Read_File (point ip[],point iq[], int &ipcounter,int &iqcounter,char name[]) // get the coordinates and the number of the p points and q points
{
//ifstream pts("point.txt");
//ifstream pts("point1.txt");
ifstream pts(name); // to read the file
string s,s1;
ipcounter=0;
iqcounter=0;
//string::const_iterator iterator1= s1.begin();
if (pts.is_open())
{
getline(pts,s);
int xx=s.rfind("<DetailedContour>"); cout<<"xx: "<<xx<<endl; // the first value at which begin the string s1
int yy=s.rfind("</DetailedContour>"); cout<<"yy: "<<yy<<endl; // the second value at which end the string s1
s1=s.substr(xx,(yy-xx));
cout<<" The Text is: \n"<<s1<<endl;
while (???????) //I don't know what should write here
{
//getline(fin,s1);
string xcor1=s1.substr(s1.find("<Node2d U=")+11,16);
string ycor1=s1.substr(s1.find("<Node2d U=")+32,16);
string dx1=s1.substr(s1.find("<Amplitude2d U=")+16,16);
string dy1=s1.substr(s1.find("<Amplitude2d U=")+37,16);
stringstream ss(xcor1); //set up a stringstream with the first string
ss >> ip[ipcounter].x; //cout<<pt.x<<endl; //extract the number
ss.clear(); //reset the stream to the beginning
ss.str(ycor1); //set the stringtream to the second string
ss >> ip[ipcounter].y; //cout<<pt.y<<endl; //extract the second number
ss.clear();
ss.str(dx1);
ss >> ip[ipcounter].dx;
ss.clear();
ss.str(dy1);
ss >> ip[ipcounter].dy;
ipcounter++;
}
}
else
{cout<<"there is a problem with opening the file...."<<endl;}
cout<<"ps................."<<endl;
for(int i=0;i<ipcounter;i++)
{
cout<<"x1:"<<ip[i].x<<" ";
cout<<"y1:"<<ip[i].y<<" ";
cout<<"dx1:"<<ip[i].dx<<" ";
cout<<"dy1:"<<ip[i].dy<<endl;
}
void iFile ()
{
int pNum=0;
int qNum=0;
char *iname;
iname= new char [20];
cout<<"Enter the name of the file to be read.."<<endl; //Plate_2.xml
cin>>iname;
Read_File (p,q,pNum,qNum,iname);
}
int main ()
{
iFile();
cin.get();
}
|