#include#include int main() { std::string myString = "Hello, world!"; const char* cString = myString.c_str(); std::cout << cString << std::endl; return 0; }
#includeIn this example, the c_str() method is used to pass the contents of the std::string "myString" to the "myFunction" function, which takes a const char pointer as its parameter. Library: This functionality is part of the standard C++ library.#include void myFunction(const char* cString) { // do something with cString } int main() { std::string myString = "Hello, world!"; myFunction(myString.c_str()); return 0; }