[wellylug] Programming Question
Jethro Carr
dodocaptain at paradise.net.nz
Mon Dec 1 16:24:06 NZDT 2003
On Mon, 2003-12-01 at 10:38, Jonathan Harker wrote:
> Hi there,
>
> Some advice... if you are using C/C++, then you may as well use C++. They are
> not the same thing, and you can learn C++ without having to learn C. This is
> handy because you can avoid learning how to fluff about reallocating memory
> for char* buffers, all the tricks to get around the abysmally insecure
> printf/scanf family of functions, and so on.
>
> Instead, you can use the C++ standard library to do string manipulation just
> as nicely as any other language, and use std::string wherever you would
> normally use a C style char* string. They handle memory allocation
> automatically for you.
>
> #include <string>
> #include <cstdlib>
> using namespace std;
>
> int main()
> {
> string myfilename = "path/to/somefile";
> string mycommand = "touch " + myfilename;
> system(mycommand);
> }
thanks - I've been programming in c++, but using a lot of old c
functions, like char.
This string function seems to be much better (I HATE using char!!)
--
-- Jethro
doodocaptain at paradise.net.nz
http://homepages.paradise.net.nz/jethroc/
http://homepages.paradise.net.nz/jethroc/cv/index.html
More information about the wellylug
mailing list