b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

c strcpy用法_c strchr函数用法_indexofstring c 实现(14)

电脑杂谈  发布时间:2017-02-28 02:04:31  来源:网络整理

如果所比较的两个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;


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-34906-14.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    • 张可久
      张可久

      升级后就连不上无线网

      • 夏娟
        夏娟

        早就和日本美国干起来了

    每日福利
    热点图片
    拼命载入中...