1. 程式人生 > >stl String常用函式

stl String常用函式

這些是我自己覺得常用的,具體檢視原文

*string(const char *s);    //用c字串s初始化

*const char *c_str()const;//返回一個以null終止的c字串,用printf(()輸出時需要

*int size()const;        //返回當前字串的大小 int length()const;       //返回當前字串的長度 bool empty()const;       

**string substr(int pos = 0,int n = npos) const;//返回pos開始的n個字元組成的字串

**iterator erase(iterator it);//刪除it指向的字元,返回刪除後迭代器的位置


**int find(char c, int pos = 0) const;//從pos開始查詢字元c在當前字串的位置

**int find(const char *s, int pos = 0)const; //從pos開始查詢字串s在當前串中的位置
**string &replace(iterator first0, iterator last0,const char *s);//把[first0,last0)之間的部分替換為字串s

**string &replace(iterator first0, iterator last0,const char *s, int n);//把[first0,last0)之間的部分替換為s的前n個字元

**string &insert(int p0,const string &s, int pos, int n);//在p0位置插入字串s中pos開始的前n個字元

**iterator erase(iterator first, iterator last);//刪除[first,last)之間的所有字元,返回刪除後迭代器的位置

*string &insert(int p0, const char *s);