Looking for a C++ file manipulation API (find, cut, paste ...)

F

for.fun

Hi all,

I have a really short time to perform a C++ development task and I
need to :

- find some string in a file
- move some text data from one place of the file to another
- replace some data in the file

The problem is my file manipulations methods have to be robust and I
have not time enough to test everything.
Having a C++ file API doing all this would help me a lot.

Do you know a portable (Windows, Unix, Linux) API which would
implement all these features ?
(I already looked in the GNU freeware directory but I did not find
what I was looking for)

Thanks in advance for your help.
 
G

Guest

Hi all,

I have a really short time to perform a C++ development task and I
need to :

- find some string in a file
- move some text data from one place of the file to another
- replace some data in the file

The problem is my file manipulations methods have to be robust and I
have not time enough to test everything.
Having a C++ file API doing all this would help me a lot.

Do you know a portable (Windows, Unix, Linux) API which would
implement all these features ?
(I already looked in the GNU freeware directory but I did not find
what I was looking for)

Manipulating text files in this manner usually involves reading the in
data from the source-file into one or more variables, perform some
operations on those variables and then overwrite the file with the
manipulated data. If you know something about the structure of the file
that will generally simplify the process.
 
J

Jack Klein

Hi all,

I have a really short time to perform a C++ development task and I
need to :

- find some string in a file
- move some text data from one place of the file to another
- replace some data in the file

The problem is my file manipulations methods have to be robust and I
have not time enough to test everything.

[snip]

If you have accepted a job of delivering a program that you do not
have enough time to test properly, you are doomed already.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
 
C

Christopher Pisz

Hi all,

I have a really short time to perform a C++ development task and I
need to :

- find some string in a file
- move some text data from one place of the file to another
- replace some data in the file

The problem is my file manipulations methods have to be robust and I
have not time enough to test everything.
Having a C++ file API doing all this would help me a lot.

Do you know a portable (Windows, Unix, Linux) API which would
implement all these features ?
(I already looked in the GNU freeware directory but I did not find
what I was looking for)

Thanks in advance for your help.

File API...lol.
The features you requested are part of the standard library, use it as your
"API". I don't see how it could possibly get any simpler than using
std::fstream and std::string. Each of those tasks is a matter of a few
lines. Your instructor probably has more information on how to use these
two.
 
J

James Kanze

I have a really short time to perform a C++ development task and I
need to :
- find some string in a file
- move some text data from one place of the file to another
- replace some data in the file
The problem is my file manipulations methods have to be robust and I
have not time enough to test everything.
Having a C++ file API doing all this would help me a lot.
Do you know a portable (Windows, Unix, Linux) API which would
implement all these features ?

The standard file handling in C++ (fstream) does not allow
random seeking in a text file. Many systems (i.e. Windows,
Unix) don't readily support moving data around in a file, nor
replacing some data with data of a different length. If at all
possible, you should simply read the file into memory, make your
changes there, write the data out to a temporary file, then
delete the original file and rename the temporary file to
replace it. If for some reason that doesn't work (e.g. the file
won't fit into memory), then you'll have to work out some stream
editing protocol: reading and copying the file, making any
changes on the fly.
 
F

for.fun

File API...lol.
The features you requested are part of the standard library, use it as your
"API". I don't see how it could possibly get any simpler than using
std::fstream and std::string. Each of those tasks is a matter of a few
lines. Your instructor probably has more information on how to use these
two.

I already works with string and fstream.
The reason why I was asking on the forum is it is not robust enough
for me.
Actually, if my app crashes in a string call (in memory), I lose the
information.
Of course, I could flush the file stream as much as I can but it would
dramatically decrease the performance.
I am sure a good compromise can be found between robustness and
performance : I need to implement something in order to do this.

Before doing the things myselfs, I wanted to know if someone already
did that kind of thing (after all, file access is a very common thing
and many people require reliability)
 
G

Guest

I already works with string and fstream.
The reason why I was asking on the forum is it is not robust enough
for me.
Actually, if my app crashes in a string call (in memory), I lose the
information.
Of course, I could flush the file stream as much as I can but it would
dramatically decrease the performance.
I am sure a good compromise can be found between robustness and
performance : I need to implement something in order to do this.

I can see only two reasons for you program to crash, either you have a
bad implementation of the standard library (which I do not find very
likely unless you run on some very obscure platform) or your code is
bad, in which case another library will not help you.
 

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,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top