C 字串處理

2021-09-19 01:38:15 字數 1047 閱讀 9821

'\0』是執行到字串尾結束,由編譯器自動加上

執行如下**段

char str = "hello c++";

cout << str<<"\n";

cout << "length: " << sizeof(str)<<"\n";

輸出為:

hello c++

length: 10

其長度是字串長度+1,編譯器自動加上『\0』;

執行以下**段

char str2 = ;

cout << str2 << "\n";

cout << "length: " << sizeof(str2) << "\n";

輸出為:

ac

length: 3

執行以下**段

char str3 = ;

cout << str3 << "\n";

cout << "length: " << sizeof(str3) << "\n";

輸出為:

ac燙燙燙燙燙ac

length: 2

由於末尾未賦值『\0』,輸出錯誤。

執行如下**段

string a = "hello\0";

string b = "hell\0o";

cout << a;

cout << b;

輸出結果為:

hello

hell

執行如下**段

char a = "hello\0";

char b = "hell\0o";

cout << a << "\n";

cout << b << "\n";

輸出結果為:

hello

hell

C 字串處理

private static regex regnumber new regex 0 9 private static regex regnumbersign new regex 0 9 private static regex regdecimal new regex 0 9 0 9 privat...

C 字串處理

string字串是char的集合,而char是unicode的 所以char可以轉化為int。字串在引數傳遞時為引用傳遞 可以使用空字串 一 字串型別轉換 1.轉為char 可以用索引器來得到字串中指定的字元,如 string mystring hello char mychars mychars ...

C 字串處理

void memccpy void dest,const void src,int c,size t n 從src所指向的物件複製n個字元到dest所指向的物件中。如果複製過程中遇到了字元c則停止複製,返回指標指向dest中字元c的下乙個位置 否則返回null。void memcpy void de...