#include#include using namespace std; int main() { string str = "Hello World!"; string mid_str = str.substr(6, 5); cout << mid_str << endl; return 0; }
#includeIn this example, the function extracts the first 5 characters of the original string. This is done through the use of the `substr()` function of the `string` package library.#include using namespace std; int main() { string str = "Hello World!"; string mid_str = str.substr(0, 5); cout << mid_str << endl; return 0; }