Okay i am working on someone elses code. They do alot of this:
char description[256]; description[0]=0;
I know this would put a \0 in the first spot of the character array. But is this even a safe way to erase a string?
Also visual studio keeps reporting memory leaks, and i’ve pretty much tied this done to the strings that are used.
Ps. Yes i know about std::string, yes i use that. This isn’t my code.
To initialize the string to 0, you could do:
that will assign 0 to every element of the array.
Just setting the first element to
0('\0') does not erase it’s contents. It doesn’t even guarantee the entire string is set to the null character.As stated by others, you can’t ‘erase’ statically-created objects until the function closes, when it gets abandoned. Technically, it’s not erased when the function is abandoned either – the stack pointer is merely changed. If you’re paranoid about the data being erased, you should iterate through the array, setting each entry to
0('\0').