std::string str = "Hello World!"; std::string sub = str.substr(6, 5); // extracts "World"
std::string str = "C++ Programming Language"; std::string sub = str.substr(0, 3); // extracts "C++"In this example, we have a string "C++ Programming Language" and we use the substr function to extract a substring starting from the 0th index and a length of 3 characters, which extracts "C++" from the original string. Package library: C++ Standard Library