• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            HUUYUU

            c++中的string用法(二)

            basic_string::compare

            如果所比較的兩個string 相等,則返回0; 操作string 大于參數(shù)string,返回

            正數(shù);操作string 小于參數(shù)string,返回負(fù)數(shù)。

            (1) 比較操作string _Str C-string _Ptr

            int compare( const basic _ string& _Str ) const;

            int compare( const value _ type* _Ptr ) const;

            int com = s.compare ( sp );

            (2) 比較操作string _Pos1 ( 下標(biāo))開始的 _Num1 個字符 與 string _Str

            比較操作string _Pos1 ( 下標(biāo))開始的 _Num1 個字符 與 C-string _Ptr

            比較操作string Pos1 ( 下標(biāo))開始的 Num1 個字符 與 Str Off ( 下標(biāo))開始 Count 個字

            int compare( size _ type _Pos1 , size _ type _Num1 , const basic _ string& _Str );

            int compare( size _ type _Pos1 , size _ type _Num1 , const value _ type* _Ptr ) const;

            int compare( size _ type _Pos1 , size _ type _Num1 , const basic _ string& _Str ,

            size _ type _Off , size _ type _Count );

            int com1 = s.compare ( 2 , 3 , sp );

            int com2 = s.compare ( 2 , 3 , c );

            int com3 = s.compare ( 1 , 3 , cs , 3 ,1 );

            basic_string::erase

            刪除string 中的一個或幾個元素。前兩個成員函數(shù),返回要被刪除的子串的下

            一個元素的iterator; 第三個函數(shù),返回刪除后的string 的引用。

            (1) 刪除string 中從 _ First _ Last 的字符

            iterator erase( iterator _First , iterator _Last );

            basic_string <char>::iterator s_Iter;

            s_Iter = s.erase ( s.begin ( ) + 3 , s.end ( ) - 1 ); // s_Iter=s.end( )

            (2) 刪除string _It 所指的字符

            iterator erase( iterator _It );

            s_Iter = s.erase ( s.begin ( ) + 5 );

            (3) 刪除string 中從 _Pos ( 下標(biāo))開始的 _Count 個字符

            basic _ string& erase( size _ type _Pos = 0, size _ type _Count = npos );

            str = s.erase ( 6 , 8 ); // str 也是 string

            basic_string::find

            尋找給定的string。返回找到的第一個string 下標(biāo)值;如果沒找到則返回npos

            (1) 找一個character _Ch 。(默認(rèn)從頭找)

            size _ type find( value _ type _Ch , size _ type _Off = 0 ) const;

            string s ( "Hello Everyone" );

            basic_string <char>::size_type index1, index2;

            static const basic_string <char>::size_type npos = -1;

            index1 = s.find ( "e" , 3 ); // index1=8, 不是 6

            index2 = s.find ( "x" ); // index2=-1

            if ( indexCh1a != npos ) cout <<indexCh1a << endl;

            else cout << "The character 'e' was not found in str1 ." << endl;

            (2) 找一個C-string。(默認(rèn)從頭找)

            size _ type find( const value _ type* _Ptr , size _ type _Off = 0 ) const;

            string s ( "Let me make this perfectly clear." );

            basic_string <char>::size_type index;

            const char *c = "perfect";

            index = s.find ( c , 5 ); // index=17

            (3) 找一個string。(默認(rèn)從頭找)

            size _ type find( const basic _ string& _Str , size _ type _Off = 0 ) const;

            string s ( "clearly this perfectly unclear." );

            basic_string <char>::size_type index;

            string sta ( "clear" );

            index = s.find ( sta , 5 ); // index=24


            引用地址:http://blog.programfan.com/trackback.asp?id=16881

            posted on 2006-09-04 18:45 HUYU 閱讀(3828) 評論(0)  編輯 收藏 引用


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            久久久久国产精品嫩草影院| 中文精品久久久久人妻| 国产情侣久久久久aⅴ免费| 久久丝袜精品中文字幕| 日本亚洲色大成网站WWW久久| 亚洲精品美女久久久久99小说| 久久久久久精品免费免费自慰| 无码人妻精品一区二区三区久久| 久久99国产精一区二区三区| 国产成人久久精品区一区二区| 久久精品国产亚洲av影院| 狠狠色狠狠色综合久久| 青青草国产精品久久| 日韩电影久久久被窝网| 东方aⅴ免费观看久久av| 久久久无码精品亚洲日韩按摩| 久久国产精品久久精品国产| 久久天天躁狠狠躁夜夜av浪潮 | 久久婷婷午色综合夜啪| 久久www免费人成看片| 韩国免费A级毛片久久| 久久国产精品国语对白| 伊人久久综合无码成人网| 93精91精品国产综合久久香蕉| 欧美日韩精品久久久免费观看| 久久精品蜜芽亚洲国产AV| 久久精品国产亚洲AV不卡| 色综合久久久久久久久五月| 狠狠综合久久综合中文88 | 亚洲精品久久久www| 久久久久久久人妻无码中文字幕爆| 久久精品国产91久久麻豆自制| 亚洲国产视频久久| 亚洲乱亚洲乱淫久久| 亚洲精品国精品久久99热一| 久久人妻少妇嫩草AV蜜桃| 久久精品中文騷妇女内射| 久久精品免费全国观看国产| 久久久久久国产精品无码下载| 久久精品久久久久观看99水蜜桃| 91性高湖久久久久|