what is use of C_str() function in C/C++

sachin picture sachin · Nov 8, 2011 · Viewed 11.1k times · Source

Can anybody tell me what is the use of c_str() function in C/C++?. In which case it is necessary to use it?.

Answer

AndersK picture AndersK · Nov 8, 2011

When you want to use your string with C-functions

string s = "hello";
printf( "your string:%s", s.c_str() );