• <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

            如果所比較的兩個(gè)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))開(kāi)始的 _Num1 個(gè)字符 與 string _Str

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

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

            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 中的一個(gè)或幾個(gè)元素。前兩個(gè)成員函數(shù),返回要被刪除的子串的下

            一個(gè)元素的iterator; 第三個(gè)函數(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))開(kāi)始的 _Count 個(gè)字符

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

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

            basic_string::find

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

            (1) 找一個(gè)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) 找一個(gè)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) 找一個(gè)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 閱讀(3827) 評(píng)論(0)  編輯 收藏 引用


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


            久久夜色撩人精品国产| 国产成人久久精品麻豆一区| 久久只这里是精品66| 久久久久久伊人高潮影院| 久久综合给久久狠狠97色| 久久狠狠色狠狠色综合| 青青草原综合久久大伊人导航| 久久亚洲AV无码精品色午夜| 狠狠色婷婷久久一区二区三区| 99久久国产亚洲高清观看2024| 亚洲精品无码久久毛片| AV无码久久久久不卡蜜桃| 国产精品九九久久免费视频| 久久午夜夜伦鲁鲁片免费无码影视 | 久久精品无码专区免费| 久久久SS麻豆欧美国产日韩| 色综合久久最新中文字幕| 亚洲欧美精品一区久久中文字幕| 国产精品18久久久久久vr| 国产精品中文久久久久久久| 国产精品久久久久久久| 无码精品久久久久久人妻中字 | 中文字幕亚洲综合久久2| 无码任你躁久久久久久老妇App| 精品久久久久久国产| 色88久久久久高潮综合影院| 深夜久久AAAAA级毛片免费看| 天天综合久久久网| 久久99毛片免费观看不卡| 乱亲女H秽乱长久久久| 久久久久一级精品亚洲国产成人综合AV区 | 久久本道伊人久久| 91久久婷婷国产综合精品青草 | 精品国产99久久久久久麻豆 | 国产69精品久久久久观看软件| 久久久免费观成人影院| 久久国产视屏| 久久亚洲欧洲国产综合| 色诱久久av| 国产激情久久久久久熟女老人| 久久婷婷五月综合97色直播|