Posted on 2011-05-04 21:04
點點滴滴 閱讀(153)
評論(0) 編輯 收藏 引用 所屬分類:
02 編程語言
string 是c++標準庫里面其中一個,封裝了對字符串的操作 把string轉換為char* 有3中方法:
1。data 如:
string str="abc";
char *p=str.data();
2.c_str 如:
string str="gdfd";
char *p=str.c_str();
3 copy 比如
string str="hello";
char p[40]; str.copy(p,5,0); //這里5,代表復制幾個字符,0代表復制的位置
*(p+5)='\0'; //要手動加上結束符 cout < <p;