Copy a string: Difference between revisions
Content deleted Content added
m →{{header|Icon}} and {{header|Unicon}}: -workswith |
|||
Line 155:
std::string s = "Hello";
// allocate memory for C string
char* cs = (char*)std::malloc(s.length()+1);
// copy the string
std::strcpy(cs, s.c_str());
Line 163:
s = cs;
// get rid of temporary buffer
std::free(cs); // delete or delete[] may not be used here</lang>
=== Using string types supplied by specific compiler-provided or external libraries ===
|