Skip to main content
gamedev.net
🔒 Locked

String to const char*

Started by mkoday 2 replies 3.5k views
Original Post
mkoday
mkoday
Is there a conversion available to make a string variable a const char* in order to pass it to functions that require that?
Oluseyi
Oluseyi

string str;
function_that_requires_const_charptr(str.c_str());
Goblin
Goblin
  
#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!"
The Goblin (madgob@aol.com)
Bunnz
Bunnz
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
Have fun BunnzPunch'n'Crunch

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.