• <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 大于參數string,返回

            正數;操作string 小于參數string,返回負數。

            (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 ( 下標)開始的 _Num1 個字符 與 string _Str

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

            比較操作string Pos1 ( 下標)開始的 Num1 個字符 與 Str Off ( 下標)開始 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 中的一個或幾個元素。前兩個成員函數,返回要被刪除的子串的下

            一個元素的iterator; 第三個函數,返回刪除后的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 ( 下標)開始的 _Count 個字符

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

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

            basic_string::find

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

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

            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。(默認從頭找)

            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。(默認從頭找)

            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) 評論(0)  編輯 收藏 引用

            无码人妻久久一区二区三区免费| 日本欧美久久久久免费播放网 | 久久免费看黄a级毛片| 久久久久亚洲精品天堂久久久久久| 久久青青草原精品国产不卡| 久久精品极品盛宴观看| 久久婷婷五月综合97色一本一本| 秋霞久久国产精品电影院| 久久人人爽人人爽人人片AV麻豆 | 天天综合久久一二三区| 亚洲午夜久久久久久久久电影网| 91精品国产综合久久久久久| 欧美久久久久久精选9999| 久久婷婷五月综合色奶水99啪| 精品久久国产一区二区三区香蕉| 亚洲精品白浆高清久久久久久| 久久电影网| 国产激情久久久久影院小草| 波多野结衣AV无码久久一区| 久久婷婷综合中文字幕| 亚洲成色WWW久久网站| 久久五月精品中文字幕| 99久久国产热无码精品免费久久久久| 少妇无套内谢久久久久| 日韩欧美亚洲国产精品字幕久久久| 国产精品一久久香蕉国产线看观看| 久久亚洲精品成人无码网站| 久久AⅤ人妻少妇嫩草影院| 久久成人国产精品二三区| 久久久av波多野一区二区| 国产精品99久久久久久宅男小说| 久久精品综合一区二区三区| 久久成人精品视频| 精品久久久久久中文字幕人妻最新| 亚洲色婷婷综合久久| 久久综合综合久久综合| 久久国产乱子伦免费精品| 久久精品人人做人人妻人人玩| 欧美喷潮久久久XXXXx| 精品久久久噜噜噜久久久| 国产精品久久久久久搜索|