關於C中的String類

2022-03-04 05:11:35 字數 647 閱讀 7970

1樓:

1.只能p=null不能*p=null否則你是給一個char賦值null

2.上面不對 應該是小寫

2樓:難得當歌對酒時

1.下面執行時為什麼會出錯!

char * p = null;

string str(p);//按上面string類的普通建構函式,這裡應該允許傳null!

你這裡的 string 是標準的 string,而不是上面的 string,上面的string當然可以接收 null,但標準的不可以。

2.上面的string類的首字母是大寫的!如果是標準c++ 標準string類,那麼我們

平時應該也可以這樣定義字串:string str;//首字母大寫!

但為什麼不可以呢?

這不是標準的 string,標準的 string 屬於 stl,定義如下:

typedef basic_string, allocator>

string;

國際化的定義是:

typedef basic_string, allocator>

wstring;

你可以把上面的 string 類引入到你的程式裡(#include即可),這樣你就可以在你的程式中使用 string 了。

C 從string類中讀取數字 字元的庫函式

你可以從string字串得到c風格字串,再用sscanf處理或者用string構造個string流,按cin使用 include include include using namespace std int main 沒有long和string互相轉換的,但是有long 還有int,double,...

C中的string和String有什麼區別

string是c 中的類,string是.netframework的類 在c ide中不會顯示藍色 c string對映為.net framework的string 如果用string,編譯器會把它編譯成string,所以如果直接用string就可以讓編譯器少做一點點工作 如果使用c 建議使用str...

c 中字元的連線,C 中string連線字元

a.c str 返回 char 可以使用 sprintf b strlen b s a.c str 也可以使用一樓方法。std string 的operator 以及 operator 如下 include include using namespace std int main 用轉換函式,從ch...