Re: append output filename
On May 25, 9:40 am, Richard Heathfield <r...@see.sig.invalid> wrote:
James Kanze said:
On May 24, 7:05 am, vj <vijayjany...@gmail.com> wrote:
<snip>
I know after reading the help file that there are functions like
strcpy and strcat, but couldn't figure out how to use them and their
exact format. Also, I am not conversant with Classes, pointers in
C++.
<snip>
Avoid the functions strcpy and strcat; they are not very safe.
In C, strcpy and strcat are both perfectly safe if used correctly.
Everything's perfectly safe "if used correctly". The question
is how difficult it is to use them correctly. Some functions,
like gets or sprintf, are impossible, or almost impossible to
use correctly. strcpy and strcat, while not as bad, require a
fair bit of care as well (and the C standard's committee has
proposed replacements, which are less dangerous). std::string
just works. Why use something that requires considerable care
and attention, when there is a simple solution which just works
available?
Do
the C++ versions of these functions have different semantics or
interfaces? </rhetorical>
C++ supports the C interfaces for reasons of C compatibility.
In C++, however, the type of a string is std::string, not
char[], and the functionality is supported with the = and the +=
operators. The result is something that is both easier to
write, and safer.
If you are a beginner, it's much, much easier to use
std::string (and std::vector, instead of T[]). The iostream
functions are a bit more complicated, but still a great deal
easier and safer to use than the FILE* mess inherited from C.
I can't agree that iostreams are easier to use than FILE *. I believe
that you believe it, but it is certainly a matter of opinion.
If the goal is a core dump, then printf is definitely easier
than anything in iostreams. But for anything useful, iostream's
beats FILE* hands down. How do you output a user defined type
using printf? How do you output to a socket? How do you read
skipping comments, or write putting a time stamp at the
beginning of each line?
In the end, FILE* isn't really even usable.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34