Regular expressions and I/O

K

Krivenok Dmitry

Hello All!
I have problem, but I don't know how to implement it.

Problem description:
I have file with records (usually record = string).
I want encapsulate all work with file in secial class "Source".

I suggest This class should contain ifstream object and GetRecord
method.

But I have several source files with different formats (very
different!)
And of course I want use my class in all cases!
Therein lies a problem!!!

I see following solution:
Constructor of Source class have 2 params:
1) Name of source file
2) Regular expression (std::string)

GetRecord method should get records from ifstream in accordance with
regular expression!

But how to implement this idea in C++???
 
M

mlimber

Krivenok said:
Hello All!
I have problem, but I don't know how to implement it.

Problem description:
I have file with records (usually record = string).
I want encapsulate all work with file in secial class "Source".

I suggest This class should contain ifstream object and GetRecord
method.

But I have several source files with different formats (very
different!)
And of course I want use my class in all cases!
Therein lies a problem!!!

I see following solution:
Constructor of Source class have 2 params:
1) Name of source file
2) Regular expression (std::string)

GetRecord method should get records from ifstream in accordance with
regular expression!

But how to implement this idea in C++???

You could use the Boost/TR1 RegEx library documented here:

http://boost.org/libs/regex/doc/index.html

Cheers! --M
 
M

mlimber

Krivenok said:
Hello All!
I have problem, but I don't know how to implement it.

Problem description:
I have file with records (usually record = string).
I want encapsulate all work with file in secial class "Source".

I suggest This class should contain ifstream object and GetRecord
method.

But I have several source files with different formats (very
different!)
And of course I want use my class in all cases!
Therein lies a problem!!!

I see following solution:
Constructor of Source class have 2 params:
1) Name of source file
2) Regular expression (std::string)

GetRecord method should get records from ifstream in accordance with
regular expression!

But how to implement this idea in C++???

You might also find the Boost Iostreams library useful, perhaps in
combination with their RegEx library:

http://boost.org/libs/iostreams/doc/index.html

Cheers! --M
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,230
Latest member
LifeBoostCBD

Latest Threads

Top