const char *c_str()const;//返回一個以null終止的c字符串
2.c_str()函數返回一個指向正規c字符串的指針,內容和string類的本身對象是一樣的,通過string類的c_str()函數能夠把string對象轉換成c中的字符串的樣式;
3.操作c_str()函數的返回值時,只能使用c字符串的操作函數,如:strcpy()等函數.因為,string對象可能在使用后被析構函數釋放掉,那么你所指向的內容就具有不確定性.
eg:
char * name[20];
string ptr = "tongnono";
strcpy(name,ptr.c_str());//c_str()返回的是一個臨時的指針變量,不能對其操作.