I have a txt file with the following data:
Point2D, [3, 2]
Line3D, [7, 12, 3], [-9, 13, 68]
Point3D, [1, 3, 8]
Line2D, [5, 7], [3, 8]
How do i actually go about storing them by removing multiple delimiters so i could extract the data out?
What i want is to read into the first line and ignore "," "[" and "]" so i could store Point2D, 3 and 2 individually. Then i go on and proceed for the second line and so on.
Also, is it possible to do this, let say for example:
The first line "Point2D, [3, 2]", when Point2D is being detected, it will store 3 and 2 into point2d.x and point2d.y.
For the second line "Line3D, [7, 12, 3], [-9, 13, 68]", it will store into the values into line3d.x,line3d.y,line3d.z and so on accordingly.
Right now i could only get it to ignore ','. This is what i've done so far:
void readData()
{
string fileName;
int i=0;
cout << "Enter file name: ";
cin >> fileName;
fstream infile;
infile.open(fileName.data());
// This will count the number of lines in the textfile.
if (! infile.is_open())
{
cerr<<"Error : " << fileName.data() <<" is not found"<<endl;
}
string line;
stringstream field;
while (getline(infile,line))
{
string f;
field<<line;
while (getline(field,f,','))
{
recordA.push_back(f);
}
field.clear();
}
cout << recordA.size() << " records read in successfully!";
infile.close();
}