|
-
Jun 22nd, 2000, 12:05 AM
#2
Monday Morning Lunatic
When you enter a string in a C++ program like that, it doesn't copy it, it merely sets the location to where in memory your program has been loaded to (plus a little bit). In order to avoid invalidating the pointer and orphaning the previous data, you need to use strcpy:
Code:
strcpy(dest_pointer, "My String is X");
This way, you change the data, not the pointer.
BTW - if you're already using STL, take a look at the string class, which is incredibly powerful, and fairly fast. It also handles reallocation properly.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
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
|