std::basic_string::substr
来自cppreference.com
< cpp | string | basic string
|
|
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
| basic_string substr( size_type pos = 0, size_type count = npos ); |
||
返回子串
[pos, pos+count)。如果被请求的子串持续时间过去结束的字符串,或者如果count == npos,返回的子[pos, size()). 目录 |
[编辑] 参数
| pos | - | |
| count | - |
[编辑] 返回值
一个字符串,它包含的子串
[pos, pos+count).[编辑] 例外
std::out_of_range if pos > size().
[编辑] 复杂度
[编辑] 示例
运行此代码
#include <string> #include <iostream> int main() { std::string a = "0123456789abcdefghij"; std::string sub1 = a.substr(10); std::cout << sub1 << '\n'; std::string sub2 = a.substr(5, 3); std::cout << sub2 << '\n'; std::string sub3 = a.substr(12, 100); std::cout << sub3 << '\n'; }
输出:
abcdefghij 567 cdefghij
[编辑] 另请参阅
| (公开成员函数) |