Re: std::string to char*
- From: "William DePalo [MVP VC++]" <willd.no.spam@xxxxxxxx>
- Date: Thu, 16 Mar 2006 12:37:41 -0500
"Boni" <nospam@xxxxxxxxxxxx> wrote in message
news:eOtRXwOSGHA.1728@xxxxxxxxxxxxxxxxxxxxxxx
const char *foo2 = foo.c_str();
Is there a reason why not do const_cast?
const char *foo2 = const_cast<char*>(foo.c_str());
Um, because it is an ugly hack? :-)
Seriously, if you could write
std::string str="hello";
char *q = const_cast<char *>( str.c_str() );
*q = 'B';
where would that leave str? Suppose you used that non-const pointer as a
target for a string copy operation where the source length exceeds the
allocation of the string? Nothing good can come of that kind of hackery.
Regards,
Will
.
- References:
- Re: std::string to char*
- From: William DePalo [MVP VC++]
- Re: std::string to char*
- From: Boni
- Re: std::string to char*
- Prev by Date: Re: how to pass array from managed to COM
- Next by Date: [MC++] ArrayList::Sort() behavior
- Previous by thread: Re: std::string to char*
- Next by thread: ManagedC++, Garabage collection and function pointer
- Index(es):
Relevant Pages
|