How to Convert string to const char * in C++

In C++, to convert a string datatype variable into const char* pointer we have a simple way.

Use the c_str function of the string class to get the const char pointer.


string my_str = “Hello, World”;
const char* conv_my_str = my_str.c_str();

That’s easy enough, right??Winking smile