read specific string in C++

Hi. i am very week in C++, i need your help...I have a text file which is my input to my program..The text file contents...


"File = E:\Files\SWwork\Point Assembly.SLDASM"
" Mates"
" Coincident1"
""
" Component = base-1"
" Type = 0"
" AlignFlag = 2"
" CanBeFlipped = False"
" MateEntType = 0"
" (x,y,z) = (5.57589607891816, 1.65404008879722, -0.144701889346493)"
" (i,j,k) = (1, 0, 0)"
" Radius 1 = 0"
" Radius 2 = 0"

" Component = cylinder-1"
" Type = 0"
" AlignFlag = 2"
" CanBeFlipped = False"
" MateEntType = 0"
" (x,y,z) = (5.57589607891816, 1.65404008879722, -0.144701889346493)"
" (i,j,k) = (1, 0, 0)"
" Radius 1 = 0"
" Radius 2 = 0"

" ------------------------------------------------"
" Coincident2"
""
" Component = base-1"
" Type = 0"
" AlignFlag = 1"
" CanBeFlipped = False"
" MateEntType = 3"
" (x,y,z) = (-5.42410392108184, -1.34595991120278, -0.144701889346493)"
" (i,j,k) = (0, 0, -1)"
" Radius 1 = 0"
" Radius 2 = 0"

" Component = cylinder-1"
" Type = 0"
" AlignFlag = 1"
" CanBeFlipped = False"
" MateEntType = 3"
" (x,y,z) = (4.07589607891816, 1.65404008879722, -0.144701889346493)"
" (i,j,k) = (-8.83369898710739E-32, 3.35432798647444E-33, 1)"
" Radius 1 = 0"
" Radius 2 = 0"

" ------------------------------------------------"
i need to read string after "component=" and the strings like (Coincident1, Coincident2, Parallel1), for example in this text the result should come like this.. base-1, cylinder-1, and Coincident1,Coincident2, Parallel1
I hav tried with this program... but it reads whole text ... please help me...


// FileInput - read blocks of data from a file
#include <fstream>
#include <iostream>
using namespace std;
ifstream* openFile(istream& input)
{
for(int i=0;i<10;i++)
{
// open the file specified by the user
char fileName[80];
cout << "Enter the name of a file" << endl;
// read input from the user in such a way
// that the input can’t overflow the buffer
input.getline(fileName, 80);
//open file for reading; don’t create the file
//if it isn’t there
ifstream* pFileStream = new ifstream(fileName);
if (pFileStream->good())
{
return pFileStream;
}
cerr << "Couldn’t find " << fileName << endl;
}
return 0;
}
int main(int nNumberofArgs, char* pszArgs[])
{
// get a file stream
ifstream* pFileStream = openFile(cin);
// read blocks of data 80 bytes at a time
char buffer[80];
while (!pFileStream->eof() && pFileStream->good())
{
// read a block - 80 is the max but gcount() returns
// the actual number of bytes read
pFileStream->read(buffer, 80);
int noBytes = pFileStream->gcount();
// do something with the block

for(int i = 0; i < noBytes; i++)
{
cout << buffer[i];
}
}
system("PAUSE");
return 0;
}





with regards
Borad


Thanks in Advance for any reply....
Last edited on
Topic archived. No new replies allowed.