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

            返回string 能放的最大元素個數。(不同于capacity

            size _ type max _ size( ) const;

            basic_string <char>::size_type cap, max;

            cap = s.capacity ( );

            max = s.max_size ( ); // max=4294967294.

            basic_string::rfind

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

            find 不同的是:rfind 默認從npos 開始找。其他相同。

            basic_string::replace

            將原string 中的元素或子串替換。返回替換后的string

            1)用string C-string 代替操作string 中從 _Pos1 開始的 _Num1 個字符

            basic _ string& replace( size _ type _Pos1 ,size _ type _Num1 , const value _ type* _Ptr );

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

            string a,b;

            string s ( "AAAAAAAA" );

            string s1p ( "BBB" );

            const char* cs1p = "CCC"

            a = s.replace ( 1 , 3 , s1p ); // s= ABBBAAAA

            b = s.replace ( 5 , 3 , cs1p ); // s= ABBBACCC

            2)用string 中從 _Pos2 開始的 _Num2 個字符,代替操作string 中從 _Pos1 開始的 _Num1 個字符

            C-string 中的 _Num2 個字符,代替操作string 中從 _Pos1 開始的 _Num1 個字符

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

            size _ type _Pos2 , size _ type );

            basic _ string& replace( size _ type _Pos1 , size _ type _Num1 ,

            const value _ type* _Ptr , size _ type _Num2 );

            string a, b;

            string s ( "AAAAAAAA" );

            string s2p ( "BBB" );

            const char* cs2p = "CCC";

            a = s.replace ( 1 , 3 , s2p , 1 , 2 ); // s= ABBAAAA

            b = s.replace ( 4 , 3 , cs2p , 1 ); // s= ABBAC

            3)用 _Count character _Ch , 代替操作string 中從 _Pos1 開始的 _Num1 個字符

            basic _ string& replace( size _ type _Pos1 , size _ type _Num1 ,

            size _ type _Count , value _ type _Ch );

            string result;

            string s ( "AAAAAAAA" );

            char ch = 'C';

            result = s.replace ( 1 , 3 , 4 , ch ); // s= ACCCCAAAA

            4)用string C-string ,代替操作string 中從 First0 Last0 的字符

            basic _ string&replace(iterator First0 ,iterator Last0 , const basic _ string& _Str );

            basic _ string&replace(iterator First0 ,iterator _Last0 , const value _ type* _Ptr );

            string s ( "AAAAAAAA" ); string s4p ( "BBB" );

            const char* cs4p = "CCC";

            basic_string<char>::iterator IterF0, IterL0;

            IterF0 = s.begin ( ); IterL0 = s.begin ( ) + 3;

            string a, b;

            a = s.replace ( IterF0 , IterL0 , s4p ); // s= BBBAAAAA

            b = s.replace ( IterF0 , IterL0 , cs4p ); // s= CCCAAAAA

            5)用string 中從 _Pos2 開始的 _Num2 個字符,代替操作string 中從 First0 Last0 的字符

            C-string 中的 _Num2 個字符,代替操作string 中從 First0 Last0 的字符

            basic _ string& replace( iterator _First0 , iterator _Last0 ,

            const value _ type* _Ptr , size _ type _Num2 );

            template<class InputIterator> basic _ string& replace(

            iterator _First0 , iterator _Last0 ,

            InputIterator _First , InputIterator _Last );

            IterF3 = s.begin ( ) + 1; IterL3 = s.begin ( ) + 3;

            IterF4 = s.begin ( ); IterL4 = s.begin ( ) + 2;

            a = s.replace ( IterF3 , IterL3 , IterF4 , IterL4 );

            b = s.replace ( IterF1 , IterL1 , cs5p , 4 );

            6)用 _Count character _Ch , 代替操作string 中從 First0 Last0 的字符

            basic _ string& replace( iterator _First0 , iterator _Last0 ,

            size _ type _Count , value _ type _Ch );

            a = s.replace ( IterF2 , IterL2 , 4 , ch );

            basic_string::swap

            交換兩個string

            void swap( basic _ string& _Str );

            s1.swap ( s2 );

            basic_string::substr

            返回從 _Off ( 下標)開始的 _Count 個字符組成的string

            basic _ string substr( size _ type _Off = 0, size _ type _Count = npos ) const;

            string s("I love you!") sub;

            sub=s.substr( ); // sub= I love you!

            sub=s.substr(1); // sub= love you!

            sub=s.substr(3,4); // sub= ove


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

            ?

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

            91精品国产综合久久久久久| 久久青青草原精品国产不卡| 97久久超碰国产精品2021| 韩国无遮挡三级久久| 久久久久九九精品影院| 国产69精品久久久久久人妻精品| 亚洲国产精品久久| 亚洲午夜久久久影院| 久久国产精品二国产精品| 久久久精品国产sm调教网站 | 日韩AV无码久久一区二区| 国产一久久香蕉国产线看观看| 伊人久久大香线蕉无码麻豆| 久久久久免费精品国产| 午夜精品久久久久久久久| 少妇被又大又粗又爽毛片久久黑人| 国产精品久久久久jk制服| 国产成人无码精品久久久性色| 久久精品亚洲男人的天堂| 国产高潮国产高潮久久久91| 日本强好片久久久久久AAA| 久久综合亚洲鲁鲁五月天| 色偷偷88欧美精品久久久| 久久天天日天天操综合伊人av| 国内精品综合久久久40p| 亚洲欧美日韩精品久久亚洲区 | 久久亚洲AV无码精品色午夜| 99久久综合国产精品二区| 久久婷婷五月综合国产尤物app| 欧美久久综合九色综合| 久久se精品一区精品二区国产| 94久久国产乱子伦精品免费| 狠狠色噜噜狠狠狠狠狠色综合久久| 久久99精品久久只有精品| 久久婷婷五月综合国产尤物app| 亚洲成色www久久网站夜月| 久久综合给合久久狠狠狠97色 | 国内精品久久久久影院一蜜桃| 日韩精品久久无码人妻中文字幕| 午夜精品久久久久久中宇| 久久男人Av资源网站无码软件|