|
-
December 15th, 2006, 08:50 AM
#1
CString concatenation
Hi GUys,
I am having a CString and append other CString to it by using the
+= operator. Normally that's ok but sometime the app crashes.
MSDN says:
"You should be aware that memory exceptions may occur whenever you use this concatenation operator because new storage may be allocated for characters added to this CString object. "
Ok, right. So how can I append a CString to another safely?
thanks
Please rate if it helps!
* The second mouse gets the cheese.
* Birthdays are good for you. The more you have, the longer you live.
* Always keep your words soft and sweet, just in case you have to eat them.
* Always read stuff that will make you look good if you die in the middle of it.
-
December 15th, 2006, 08:53 AM
#2
Re: CString concatenation
The chances that a CString += operation causing a crash are pretty close to zero. Unless your string are millions of characters long, I would suspect that if you're having problems the cause is somewhere else.
-
December 15th, 2006, 08:58 AM
#3
Re: CString concatenation
Yes it used to work fine. Now, when I'm debugging the app, sometimes I get an error at that location.
it is something like: (the aStr has the sufficient length so the delete is not the problem.
Code:
aStr.Delete(0,8);
formatted += " Bank: ";
formatted += aStr.Left(2);
formatted += '\n';
//bank
aStr.Delete(0,2);
formatted += " Address: ";
formatted += aStr.Left(4);
formatted += '\n';
//length
aStr.Delete(0,4);
formatted += " Length: ";
formatted += aStr.Left(4);
formatted += '\n';
Please rate if it helps!
* The second mouse gets the cheese.
* Birthdays are good for you. The more you have, the longer you live.
* Always keep your words soft and sweet, just in case you have to eat them.
* Always read stuff that will make you look good if you die in the middle of it.
-
December 15th, 2006, 09:03 AM
#4
Re: CString concatenation
Looking at that code, the most like problem is that it's actually Left blowing up if aStr is too short.
Have you tried the debugger?
-
December 15th, 2006, 09:30 AM
#5
Re: CString concatenation
Thanks! I'll take a look at that.
Please rate if it helps!
* The second mouse gets the cheese.
* Birthdays are good for you. The more you have, the longer you live.
* Always keep your words soft and sweet, just in case you have to eat them.
* Always read stuff that will make you look good if you die in the middle of it.
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
|