• Advertisement

Archived

This topic is now archived and is closed to further replies.

String to const char*

This topic is 5933 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there a conversion available to make a string variable a const char* in order to pass it to functions that require that?

Share this post


Link to post
Share on other sites
Advertisement
  
#include <string>

std::string mr_string;

mr_string.c_str(); // null-terminated

mr_string.data(); // not null-terminated



Hope that helps!

-----------------
The Goblin (madgob@aol.com)
-----------------
"Before critisizing somebody, walk a mile in their shoes. That way, when you do critisize them, not only will you be a mile away, but you''ll also have their shoes!"

Share this post


Link to post
Share on other sites
Hi

You can write your own string class with automatic conversion

=>
CString::operator const char*(void) const
{
return( str.c_str());
};

Have fun
Bunnz
www.bunnz.com


(Bunnz: had to edit this post cos your signature was messing up the thread: missing quote at the end of the HREF - Kylotan)

Edited by - Kylotan on November 22, 2001 10:32:39 PM

Share this post


Link to post
Share on other sites

  • Advertisement