Hello,
I try to use boost regex . I don't have a lot of experience of using
boost regex . Boost regex examples aren't so explicit for me. So I need
some help to parse this example file.
Point(1) = {0,0,0,0.1};
Point(2) = {1,0,0,0.1};
Point(3) = {0,1,0,0.1};
Point(4) = {1,1,0,0.1};
Line(1) = {1,2};
Line(2) = {2,4};
Line(3) = {4,3};
Line(4) = {3,1};
Line Loop(5) = {2,3,4,1};
Plane Surface(6) = {5};
I can't read each informations to use it after.
I can't match for use IdentificationNumber of Point(IdentificationNumber).
Actually my code look so :
/*
g++ -Wall -O2 -o ifstream ifstream.cc
*/
#include <iostream>
#include <fstream>
#include <string>
/* boost regex header */
#include
using namespace std;
using namespace boost;
int
main (int argc, char argv[])
{
char buffer[256];
string filename;
string inputstring;
cout << "Input filename ";
cin >> filename;
ifstream readfile (filename.c_str (), ios::in);
if (!readfile.is_open ())
{
cout << "Error opening file" << endl;
return 0;
}
regex exPoint ("Point");
regex exLine ("Line");
regex IdentificationNumber ("[:digit:]");
while (!readfile.eof ())
{
readfile.getline (buffer, 200);
inputstring = buffer;
if (regex_search (inputstring, exPoint))
{
cout << "Point" << endl;
smatch result;
if (regex_search
(inputstring, result, IdentificationNumber))
{
cout << "Identification Number " << result << endl;
}
else
cout << "Error regex_match" << endl;
}
if (regex_search (inputstring, exLine))
{
cout << "Line" << endl;
}
cout << buffer << endl;
}
readfile.close ();
return (0);
}
Thank you for help. Best regards
hackervalley
http://hackervalley.free.fr