C++ string類常用的函式
阿新 • • 發佈:2018-12-07
字串是一種線性表,有著廣泛的應用,比如:文字編輯 、 情報檢索 、 拼寫檢查 、 網際網路搜尋引擎和自然語言翻譯等。
- string append(const char *s); 將字串 s 追加到本字串的末尾
- string assign(const char *s); 將字串 s 賦給本字串
- int compare(const string & str)const; 比較兩個字串是否相同
- string& insert(unsigned int p0,const char *s); 將字串 s 插入到本字串 p0 的位置
- string substr(unsigned int pos,unsigned int n)const; 取出該字串從 pos 位置開始的 n 個字元,並返回新的字串
- unsigned int find(const basic_string& str)const; 查詢子字串str在本字串中第一次出現的位置
- unsigned int length()const; 獲得本字串的長度
- void swap(string & str); 本字串與字串str進行交換