473,385 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

C++ Class to do File Text Based Operations

Hi,

I am looking for a possible C++ File class that allows to do standard
"Perl Like" operations on structured data files in ASCII text.

For example:

1) Get the first and third fields from each line into a string obj
2) Get ALL "words" in a "line" of the file

etc...

Basically, anything you would be able to do from a Perl script, but
thru C++. I am looking to use it in my program and I know there are
better programmers than me out there, so I thought I will check first!

THanks in advance!
Anand
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Jul 23 '05 #1
4 1537
"anand" <wr********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I am looking for a possible C++ File class that allows to do standard
"Perl Like" operations on structured data files in ASCII text.

For example:

1) Get the first and third fields from each line into a string obj
2) Get ALL "words" in a "line" of the file

etc...

Basically, anything you would be able to do from a Perl script, but
thru C++. I am looking to use it in my program and I know there are
better programmers than me out there, so I thought I will check first!


The two operations above can be written with a standard C++ istream.
But you may want to consider using a regular expressions library
for C++. Such as boost::regex http://www.boost.org/libs/regex/doc/.
Ivan

NB: it is often redundant to post to both clc++ and clc++.moderated.
If you're concerned by off-topic replies/threads, use the moderated group.
If you want a quicker answer, clc++ is usually best.
But posting to both NGs usually will delay the appearance of your
post and reply on clc++ as well.

--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <> http://www.brainbench.com
Jul 23 '05 #2
anand wrote:
Basically, anything you would be able to do from a Perl script, but
thru C++.


That will be very difficult. You need to implement a C++ version of all
modules in CPAN, at least.

If you want to use all Perl machinery, the easiest way will be to embed perl
in your program.

--
Salu2
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Jul 23 '05 #3

"anand" <wr********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hi,

I am looking for a possible C++ File class that allows to do standard
"Perl Like" operations on structured data files in ASCII text.

For example:

1) Get the first and third fields from each line into a string obj
2) Get ALL "words" in a "line" of the file

etc...

Basically, anything you would be able to do from a Perl script, but
thru C++. I am looking to use it in my program and I know there are
better programmers than me out there, so I thought I will check first!


Check out:

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

http://www.boost.org/libs/spirit/index.html

http://www.boost.org/doc/html/string_algo.html

http://www.boost.org/libs/filesystem/doc/index.htm

I'm totally unfamiliar with Perl, but the above libraries offer powerful C++
text and filesystem processing.

Jeff Flinn

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Jul 23 '05 #4
On Sat, 28 May 2005, anand wrote:
Hi,

I am looking for a possible C++ File class that allows to do standard
"Perl Like" operations on structured data files in ASCII text.

For example:

1) Get the first and third fields from each line into a string obj
2) Get ALL "words" in a "line" of the file

etc...

Basically, anything you would be able to do from a Perl script, but
thru C++. I am looking to use it in my program and I know there are
better programmers than me out there, so I thought I will check first!

THanks in advance!
Anand


Couple of functions I wrote do do just what you ask. Excep no regular
expressions. THere is a split and a sub. You could extend these to use pcre
lib and get the location of a regular expression. I just haven't carried it
that far YET :)

#include <string>
#include <sstream>
#include <locale>

bool StrSplit(const string in,char delim,vector<string>& out)
{
if (in.empty()) return false;
istringstream iss(in);
string token;
out.clear();
while(getline(iss, token, delim))
out.push_back(token);
return true;
}

bool StrSub(string& cp,string sub_this,string for_this,int num_times)
{
int i,loc;
if (cp.empty())
{
cp = sub_this;
return true;
}
if (for_this.empty()) return false;
for (i = 0; i NE num_times; i++)
{
loc = cp.find(for_this,0);
if (loc GE 0) cp.replace(loc,for_this.length(),sub_this);
else return true;
}
return true;
}

___ _ ____ ___ __ __
/ _ )(_) / /_ __ / _ \___ _/ /_/ /____ ___
/ _ / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/ \_,_/\__/\__/\___/_//_/
/___/
Texas Instruments ASIC Circuit Design Methodology Group
Dallas, Texas, 214-480-4455, b-******@ti.com

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: mir nazim | last post by:
hi. i want to know if there is any flat-file relational database system available for python. i require it in a project. it should have following capabilities: 1. should be small and compact on...
1
by: Andrew James | last post by:
All, I'm having some trouble with understanding python's importing behaviour in my application. I'm using psyco to optimise part of my code, but I'm not sure whether it inherits throughout the...
5
by: reddy | last post by:
I am trying to insert a node into an XMLFile. using XMLTextwriter. My Question is Is it possible to do without using XMLDocument. Because its loading all the the file into memory. I just want to...
10
by: cmk128 | last post by:
Hi I am going to implement a new string class for my os, do you have any idea to enhance of standard c++ string class? If compare c++ string class with CS++ CString class and java String class,...
2
by: John Mullin | last post by:
We are having a problem which appears similar to a previous posting: http://groups.google.com/groups?hl=en&lr=&frame=right&th=d97f552e10f8c94c&seekm=OZw33z9EDHA.2312%40TK2MSFTNGP10.phx.gbl#link1 ...
68
by: vim | last post by:
hello everybody Plz tell the differance between binary file and ascii file............... Thanks in advance vim
38
by: JTL | last post by:
I have learnt java before and now begin to learn c++ what puzzle me is that seem that different SDKs(c++builder, vs.net, gcc..) has its own class library we know that in java there are only one...
5
by: felciano | last post by:
Hello -- Is there a convention, library or Pythonic idiom for performing lightweight relational operations on flatfiles? I frequently find myself writing code to do simple SQL-like operations...
2
by: kodart | last post by:
Introduction Performance is the main concern to most server application developers. That’s why many of them anticipate using .NET platform to develop high performance server application regardless...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.