c++ string to char array

#include <iostream>
#include <string>

int main() {
    std::string str = "Hello, World!";

    // Step 1: Get the length of the C++ string
    int length = str.length();

    // Step 2: Create a character array with enough space
    char charArray[length + 1];

    // Step 3: Copy the contents of the C++ string to the character array
    //         using the c_str() function
    std::strcpy(charArray, str.c_str());

    // Step 4: Print the original C++ string
    std::cout << "Original C++ string: " << str << std::endl;

    // Step 5: Print the converted character array
    std::cout << "Converted char array: " << charArray << std::endl;

    return 0;
}