Help in how to call txt file different string

Here is below the program i tried! and I couldn't call (vertex, segment, and radius). The txt file has a format:

vertex 1 2 4
vertex 2 4 3
vertex 2 4 5
vertex 3 4 5
segment 1.3 2 2
radius 1

Any help will be appreciated!!!!!!



/program to generate vertex for triangualtion of plate with hole
#include <iostream>
#include <math.h>
#include <fstream>
#include <vector>
#define PI 3.14159265
using namespace std;
int main()
{
vector<double> x1;
vector<double> y1;
vector<double> z1;
vector<double> x11;
vector<double> y11;
vector<double> z11;
double a,b,xa,ya,za,xb,yb,xc,yc,xd,yd,xe,ye,xf,yf,xg,yg,xh,yh,r;
//Read the file from
ifstream inputFile("plate-with-hole.txt");
ofstream outputFile("tes-plate-hole.txt");
double x,y,z,n,xx1,yy1,zz1;
string vertex;
cout<<"Enter the radius of the hole (r):"<<endl;
cin>>r;
cout<<"Enter the vertex of point a: xa:"<<endl;
cin>>xa;
cout<<"Enter the vertex of point a: ya:"<<endl;
cin>>ya;
cout<<"Enter the vertex of point a: za:"<<endl;
cin>>za;
while(inputFile>>vertex>>x>>y>>z)
{
x1.push_back(x);
y1.push_back(y);
z1.push_back(z);
}
ifstream inputFile1("plate-with-hole.txt");
while(inputFile1>>segment>>x11>>y11>>z11)
{
x11.push_back(xx1);
y11.push_back(yy1);
z11.push_back(zz1);
}
while(inputFile>>radius>>r)
{
r1.push_back(r);
}
//outputFile<<vertex<<" "<<x1[0]<<" "<<y1[0]<<" "<<z1[0]<<endl;

if(z1[0]==z1[1]==z1[2]==z1[3])
{
xb=x11[0]+r; yb=y11[0]-r; xc=x11[0]+2*r; yc=y11[0]; xd=x11[0]+r; yd=y11[0]+r; xe=x11[0]+r; ye=y1[2];xf=x1[1]; yf=y11[0]; xg=x1[0]; yg=y11[0]; xh=x11[0]+r;yh=y1[0];
}
else
{
cout<<"It is not in xy plane so, consider another plane: sorry"<<endl;
}

outputFile<<vertex<<" "<<xg<<" "<<yg<<" "<<z1[0]<<endl;

for(double i=180;i<=270;i=i+10)
{
a=xa+r+r*cos(i*(PI/180));
b=ya+r*sin(i*(PI/180));
outputFile<<vertex<<" "<<a<<" "<<b<<" "<<z1[0]<<endl;
}
outputFile<<vertex<<" "<<xh<<" "<<yh<<" "<<z1[3]<<endl;
outputFile<<vertex<<" "<<x1[0]<<" "<<y1[0]<<" "<<z1[0]<<endl;

//second quarter

outputFile<<vertex<<" "<<xh<<" "<<yh<<" "<<z1[0]<<endl;

for(double i=270;i<=360;i=i+10)
{
a=xa+r+r*cos(i*(PI/180));
b=ya+r*sin(i*(PI/180));
outputFile<<vertex<<" "<<a<<" "<<b<<" "<<z1[0]<<endl;
}
outputFile<<vertex<<" "<<xf<<" "<<yf<<" "<<z1[3]<<endl;
outputFile<<vertex<<" "<<x1[1]<<" "<<y1[1]<<" "<<z1[1]<<endl;

//third quarter

outputFile<<vertex<<" "<<xf<<" "<<yf<<" "<<z1[0]<<endl;

for(double i=0;i<=90;i=i+10)
{
a=xa+r+r*cos(i*(PI/180));
b=ya+r*sin(i*(PI/180));
outputFile<<vertex<<" "<<a<<" "<<b<<" "<<z1[0]<<endl;
}
outputFile<<vertex<<" "<<xe<<" "<<ye<<" "<<z1[3]<<endl;
outputFile<<vertex<<" "<<x1[2]<<" "<<y1[2]<<" "<<z1[2]<<endl;
//Fourth quarter

outputFile<<vertex<<" "<<xe<<" "<<ye<<" "<<z1[0]<<endl;

for(double i=90;i<=180;i=i+10)
{
a=xa+r+r*cos(i*(PI/180));
b=ya+r*sin(i*(PI/180));
outputFile<<vertex<<" "<<a<<" "<<b<<" "<<z1[0]<<endl;
}
outputFile<<vertex<<" "<<xg<<" "<<yg<<" "<<z1[3]<<endl;
outputFile<<vertex<<" "<<x1[3]<<" "<<y1[3]<<" "<<z1[3]<<endl;
system ("PAUSE");
}






you can try this .
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
ifstream inputFile("plate-with-hole.txt");
ofstream outputFile("tes-plate-hole.txt");
stringstream str_seperator;
string line ; 
	while(inputFile.is_good())
	{
		gelline( inputFile , line );
		str_seperator<<line ; 
		str_seperator>>vertex>>x>>y>>z
			if(  vertex != "radious" )
		{
			x1.push_back(x);
			y1.push_back(y);
			z1.push_back(z); 
		}else if ( vertiex == "segment")
		{
				xx1  = x ; 
				yy1 = y ; 
				zz1 = z ; 

					x11.push_back(xx1);
					y11.push_back(yy1);
					z11.push_back(zz1);
			
		}
	}else
	{
		r1 = x;
	}

if(z1[0]==z1[1]==z1[2]==z1[3])
{
xb=x11[0]+r; yb=y11[0]-r; xc=x11[0]+2*r; yc=y11[0]; xd=x11[0]+r; yd=y11[0]+r; xe=x11[0]+r; ye=y1[2];xf=x1[1]; yf=y11[0]; xg=x1[0]; yg=y11[0]; xh=x11[0]+r;yh=y1[0];
}
else
{
cout<<"It is not in xy plane so, consider another plane: sorry"<<endl;
}
Thank you: bleucoder for your help, I tried with yr suggestion but, i got an error :'struct std::ifstream' has no member named 'is_good' . This happened in line : while(inputFile.is_good()). Do i need another header file? Appreciate yr help again
I tried with the following header files,

//program to generate vertex for triangualtion of plate with hole
#include <iostream>
#include <math.h>
#include <fstream>
#include <vector>
#include <sstream>
#define PI 3.14159265
using namespace std;
int main()
{
vector<double> x1;
vector<double> y1;
vector<double> z1;
vector<double> x11;
vector<double> y11;
vector<double> z11;
double x,y,z,n,xx1,yy1,zz1;
string vertex;
string segment;
string radius;
double a,b,xa,ya,za,xb,yb,xc,yc,xd,yd,xe,ye,xf,yf,xg,yg,xh,yh,r;
//Read the file from
ifstream inputFile("plate-with-hole.txt");
ofstream outputFile("divided-plate-hole.txt");
stringstream str_seperator;
string line ;
while(inputFile.is_good())
{
getline( inputFile , line );
str_seperator<<line ;
str_seperator>>vertex>>x>>y>>z
if( vertex != "radius" )
{
x1.push_back(x);
y1.push_back(y);
z1.push_back(z);
}else if ( vertex == "segment")
{
xx1 = x ;
yy1 = y ;
zz1 = z ;

x11.push_back(xx1);
y11.push_back(yy1);
z11.push_back(zz1);

}
else
{
r1 = x;
}
}

if(z1[0]==z1[1]==z1[2]==z1[3])
{
xb=x11[0]+r; yb=y11[0]-r; xc=x11[0]+2*r; yc=y11[0]; xd=x11[0]+r; yd=y11[0]+r; xe=x11[0]+r; ye=y1[2];xf=x1[1]; yf=y11[0]; xg=x1[0]; yg=y11[0]; xh=x11[0]+r;yh=y1[0];
}
else
{
cout<<"It is not in xy plane so, consider another plane: sorry"<<endl;
}
}
.is_good() should be .good()
Thank you very much!!!
Topic archived. No new replies allowed.