string比較字符串某個指定的字符串

string data="eewertyui";

比較索引3字母是e的話,移除該字母,不是則忽略。

string data="eqwertyui";
if(data.compare(3,1,"e",0,1)==0)
{
	data=data.erase(3,1);
}

compare()函數  

類 basic_string 的成員函數 compare() 的原型如下:

int compare (const basic_string& s) const;
int compare (const Ch* p) const;
int compare (size_type pos, size_type n, const basic_string& s) const;
int compare (size_type pos, size_type n, const basic_string& s,size_type pos2, size_type n2) const;
int compare (size_type pos, size_type n, const Ch* p, size_type = npos) const;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章