char *string = new char[10];
...
delete [] string;
is the C++ equvalent to
char *string = (char*)malloc(10);
...
free(string);
How can I realloc() the string to 20 characters, preserving its contents?
What is the C's realloc() equivalent in C++?
There isn't a realloc() or a redim() in C++. You have to declare a new char[20]. Copy the old one to the new one. And finally, delete the old one.
Reply:with built-in functionality you can't...you want to use one of the common libraries such as cstring which can do resizing etc.
Reply:In C++ you can use STL's as these inbuilt data structures does a lot of work with minimal code.
snow of june
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment