About allocated memory in C++
I use a lot of strings and need to make my code efficient with memory.
The first thing is how is the best way to use strings when you don't now the size of it or when you need to use pointer so you can use as return value? The second thing. Lets say I have a function that allocates memory, fills it with a string and returns a pointer to that memory. The calling function uses this function as argument in something like strcmp()? How can I now free that memory after I am done? |
What you describing is C strings. If your going to be using unknow size strings all over your code in C++ I suggest you use the string class thats in the STL.
Belows an example. Code:
#include <iostream> |
thx£º£©
|
All times are GMT -5. The time now is 06:31 PM. |