In C++, you cannot directly use slicing like you can in Python to extract a range of characters from a string. However, you can achieve similar functionality using C++'s standard library functions. To print a substring of a C++ string from index 2 to 5 (inclusive), you can do the following: #include #include int main() { std::string text = "example text"; // Define the start and end indices for the substring int start = 2; int end = 5; // Check if the indices are within bounds if (start >= 0 && start < text.length() && end >= start && end < text.length()) { // Extract the substring and print it std::string sub = text.substr(start, end - start + 1); std::cout << sub << std::endl; } else { std::cout << "Invalid indices" << std::endl; } return 0; } In this code: 1. We include the necessary headers for working with strings and input/output in C++. 2. We define the original string text. 3. We specify the start and end indices to define the range you want to extract (2 to 5). 4. We check if the indices are valid (within the bounds of the string). 5. If the indices are valid, we use the substr function to extract the substring from start to end and then print it. Keep in mind that in C++, string indices are 0-based, so the first character is at index 0, the second at index 1, and so on.