#includestd::string str = "Hello World"; std::string rightSubstring = str.substr(str.size()-5); // returns "World"
#includeThe CStdString Right function is part of the C++ Standard Library and is defined in the header file "string". It is available in most C++ development environments including Visual Studio, GCC, and Clang.#include #include int main() { std::string str = "C++ is awesome"; int length = 3; // length of the substring to be extracted std::string rightSubstring = str.substr(std::max(0, (int)str.size()-length)); // returns "ome" std::cout << rightSubstring << std::endl; return 0; }