std::basic_string::substr
提供: cppreference.com
< cpp | string | basic string
| 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().
[編集] 計算複雑性
countに比例
[編集] 例
このコードを実行します
#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
[編集] 参考
| 文字をコピーします (パブリックメンバ関数) | |