how to get a section of a string in c++

#include <iostream>
#include <string>

int main() {
    // Step 1: Declare a string
    std::string originalString = "Hello, World!";

    // Step 2: Specify the starting index and length of the desired section
    size_t startIndex = 7; // Starting index of the section
    size_t sectionLength = 5; // Length of the section

    // Step 3: Use the substr() function to extract the desired section
    std::string extractedSection = originalString.substr(startIndex, sectionLength);

    // Step 4: Display the result
    std::cout << "Original String: " << originalString << std::endl;
    std::cout << "Extracted Section: " << extractedSection << std::endl;

    return 0;
}