C++字串

來源:互聯網
上載者:User

標籤:strstr   標準庫   ...   位置   大於   插入   bst   連接字串   har   

C++字串:
1.字元數組:使用null字元‘\0‘終止字串 char greeting[6] = {‘H‘, ‘e‘, ‘l‘, ‘l‘, ‘o‘, ‘\0‘}; 或 char greeting[] = "Hello";
函數操作:
1strcpy(s1, s2);複製字串 s2 到字串 s1。
2strcat(s1, s2);連接字串 s2 到字串 s1 的末尾。
3strlen(s1);返回字串 s1 的長度。
4strcmp(s1, s2);如果 s1 和 s2 是相同的,則返回 0;如果 s1<s2 則傳回值小於 0;如果 s1>s2 則傳回值大於 0
5strchr(s1, ch);返回一個指標,指向字串 s1 中字元 ch 的第一次出現的位置。
6strstr(s1, s2);返回一個指標,指向字串 s1 中字串 s2 的第一次出現的位置。
2. String 類:標準庫標頭檔<string>
函數操作:
1str2 = str1;複製字串 s2 到字串 s1。
2str3 = str1 + str2;連接字串 s2 到字串 s1 的末尾。
3str1.size();返回字串 s1 的長度。
4 str1.append()在字串的末尾添加字元
5str1.find() 在字串中尋找字串
6 str1.insert() 插入字元
7 str1.length() 返回字串的長度
8 str1.replace() 替換字串
9 str1.substr() 返回某個子字串
10 ...

C++字串

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.