Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

string to (const char*)

Status
Not open for further replies.

mather

Programmer
Mar 24, 2002
3
ZA
this maybe a stupid question, but is there a way to convert a string to a const char*.

Problem is that the input i recieve is string but the libraries in need to use, wants const char*
 
There is a string::c_str() method, it returns a c-style string equivalent to the string.

eg
string str("hello");

printf("%s\n", str.c_str());

if you want to use it in place and have a function func() that returns a string you can always do something like:

printf("%s\n", func().c_str());
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top