c++11 相当の文字列型全般
example code | description | remark |
---|---|---|
string a; | 空の文字列を生成 | |
string b = "example"; | 右辺に渡された文字列で生成 | |
string c( b, 1, 3 ); | 元になる文字列 b の1番目から3番目の部分文字列から文字列を生成 | |
string d( "example", 2 ); | 文字列先頭2文字からなる文字列を生成 | |
string e( 10, 't' ); | 10個の文字 't' からなる文字列を生成 | |
string f = { 'e, 'x', 'a' }; | 文字の初期化子リストから文字列を生成 | |
string g = b; | string 変数 b のコピーを構築 | |
string i( b.begin(), b.end() ); | string 変数 b の iterator によって指定された範囲から文字列を生成 | 逆順を指定すると、gcc 4.9.2 では basic_string::_S_create が "std::length_error" でコアダンプする |
== != < > <= >=
basic_str::substr( size_type pos = 0, size_type n = npos ) const;
size_type find( const basic_string& str, size_type pos = 0 ) const noexcept; str: 検索文字列 pos: 検索開始位置 n : 検索する文字列の長さ size_type find( const CharT* s, size_type pos, size_type n ) const; s : 検索文字列 pos: 検索開始位置 n : 検索する文字列の長さ size_type find( const CharT* s, size_type pos = 0 ) const noexcept; s : 検索文字列 pos: 検索開始位置 n : 検索する文字列の長さ size_type find( CharT c, size_type pos = 0 ) const noexcept; c : 検索文字 pos: 検索開始位置 n : 検索する文字列の長さ
size_type rfind( const basic_string& str, size_type pos = npos ) const noexcept; str: 検索文字列 pos: 検索開始位置 n : 検索する文字列の長さ size_type rfind( const CharT* s, size_type pos, size_type n ) const; s : 検索文字列 pos: 検索開始位置 n : 検索する文字列の長さ size_type rfind( const CharT* s, size_type pos = npos ) const; s : 検索文字列 pos: 検索開始位置 n : 検索する文字列の長さ size_type rfind( CharT c, size_type pos = npos ) const noexcept; c : 検索文字 pos: 検索開始位置 n : 検索する文字列の長さ