#include#include int main() { std::string my_str = "Hello World"; const char* char_ptr = my_str.getCharPointer(); std::cout << char_ptr << std::endl; // Output: Hello World return 0; }
#includeIn this example, we obtain a const char pointer to the first character in "Goodbye". We then print the dereferenced value of the pointer to the console, which gives us the first character "G". The getCharPointer function is a member of the standard C++ library. It is part of the string class.#include int main() { std::string my_str = "Goodbye"; const char* char_ptr = my_str.getCharPointer(); std::cout << *char_ptr << std::endl; // Output: G return 0; }