From std::string, std::string::substrwill create a new one std::stringfrom the existing one, given the initial index and the length. It should be trivial to determine the necessary length, given the final index (although this will depend on whether the final index is included or excluded).
If you are trying to create a substring from a C-style string (NUL-end char), you can use std::string(const char* s, size_t n). For example:
const char* s = "hello world!";
size_t start = 3;
size_t end = 6;
std::string substring(s + start, end - start);
source
share