|
-
October 21st, 2010, 07:37 AM
#5
Re: is there any problem if I set a char to '\0' within a string?
 Originally Posted by Feoggou
sorry for asking, but for whom is this message, for me or for laserlight?
I only need to make sure that delete[] deletes the characters after '\0' as well. I'm using the string with windows API functions. the display is correct (I've had no problems with it).
It was for you, but it was irrelevant. I hadn't taken the time to read your full message, sorry. I thought you were talking about std::string, when in fact you were talking about plain old char arrays.
The delete will be correct, as delete does not look at the object contents contents to know the bounds. However, for mostly every other function of the type strlen, or strcopy, you have to make sure your string is null terminated.
Also, consider using std::string, arrays are evil.
Is your question related to IO?
Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|