substr function in c++

The substr function is a function of the string class

grammar:

#include <string>
basic_string substr( size_type index, size_type num = npos );

Usage:
substr() returns a substring of this string, starting at index, num characters long. If not specified, will default to string::npos. Thus, the substr() function will simply return the remaining string starting at index.

Example:

    string s("What we have here is a failure to communicate");

    string sub = s.substr(21);

    cout << "The original string is " << s << endl;
    cout << "The substring is " << sub << endl;

output:

    The original string is What we have here is a failure to communicate
    The substring is a failure to communicate

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326398444&siteId=291194637