C STL學習筆記2 String

2021-06-18 12:15:35 字數 1015 閱讀 9987

string是c語言char陣列的變形和封裝,作為乙個結構體存在,具有許多整合的操作,包括初始化、插入、刪除、清空、計數、判斷是否空等

一、string建立

#include

#include

using namespace std;

int main()

二、插入

三、string的部分替換

#include

#include

using namespace std;

int main()

{string s="what's your name?";

cout<<"原來的字串"<#include

#include

using namespace std;

int main()

{string s="what's your name?my name is tom.how do you do?fine,thanks. ";

int n=s.find("you");//從開始找到的第乙個you位置

cout<<"the first pos of you is "《五、刪除(erase())

# include

#include

using namespace std;

int main()

{string s1="how are you?";

s1.erase(s1.begin(),s1.begin()+3);

cout<<"刪除後的s1"《六、比較和反轉

#include

#include

#include

using namespace std;

int main()

{string s1="this";

string s2="that";

if(s1>s2)cout<<"s1>s2";//過載過的》<==

else if(s1s2)cout<<"s1>s2";

else if(s1

Redis學習筆記(2) string 型別值訪問

在redis學習筆記 1 中,我們提到redis是屬於key value儲存結構,value儲存的型別有string 字串 list 鍊錶 set 集合 和zset 有序集合 在接下去的學習中,我們將學習value值的儲存。那麼我們先學習比較簡單的儲存型別 string型。說明 由於採用的平台是.n...

Python基礎筆記2(string字串)

string 字串 表示一段文字 字串表示時 1.單引號 2.雙引號 使用注意當字串內有單引號或雙引號可以使用如下的方式 print let s go 通過雙引號直接輸出單引號文字 輸出let s go print guang 通過單引號直接輸出雙引號文字 輸出 guang print let s ...

第十八章 2string字串

char型字串是c語言風格的字串,它是用陣列來儲存字串的,但是到了c 時代,由於延生了類,出現了一種c 風格的字串,也就是string型字串 這種風格的字串是用string類來定義字串的,因此要使用這個string類,我們必須在程式開頭新增標頭檔案string,string類存在於名字空間std中,...