共有成员函数
<string>
std::string::substr
string substr (size_t pos = 0, size_t len = npos) const;
产生子串
返回一个新建的
初始化为string对象的子串的拷贝
string对象。
子串是,在字符位置pos开始,跨越len个字符(或直到字符串的结尾,以先到者为准)对象的部分。
参数
-
pos
-
第一个字符的位置被复制为子串。
如果这是等于字符串的长度,该函数返回一个空字符串。
如果这是大于字符串的长度,它会抛出out_of_range。
注意:第一个字符表示为值0(不是1)。
len
-
字符数在子包括(如果字符串是短,尽可能多的字符可以在需要使用)。
字符串::非营利值表示的所有字符,直到字符串的结尾。
size_t is an unsigned integral type (the same as member type string::size_type ).
返回值
A string object with a substring of this object.Example
| |
Output:
think live in details. |