On 25/01/07, Adriano Crestani <[EMAIL PROTECTED]> wrote:
I'm begginer with C++ and I would like to know the best way to obtain a
char* from a string object, for example:
string name = "Alice";
char* namePtr = (char*) string; // this is not possible : (
Obs.: I'm needing a char* and not a const char* pointer
Thanks.
Adriano Crestani
std::string has a .c_str() method to return the const char*
const char* namePtr = name.c_str();
Why do you need char* and not const char*? You could cast the value to
char* but it is const for a good reason... you should not use c
functions to manipulate the characters in std:string!
You can take a copy of the string using strdup.
Cheers,
--
Pete
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]