Can I free the memory of the char* pointed string after I have convert it to a std::string? For example:
char* c_string; c_string = strdup("This is a test"); std::string cpp_string; cpp_string(c_string); free(c_string); /* can I call free here? */ Yes. The std::string constructor makes a copy of the string passed to it.
See constructor #4 on this page.
string (const char* s); // from c-string from c-string
Copies the null-terminated character sequence (C-string) pointed by s.
std:string.std::stringis perfectly valid in C++. You probably just forgot to include<string>.std:stringinstead ofstd::string. See the typo?