- 論壇徽章:
- 11
|
本帖最后由 zylthinking 于 2011-12-30 10:21 編輯
giantchen 發(fā)表于 2011-12-30 10:04 ![]()
回復(fù) 5# zylthinking
我返回去仔細(xì)想了想, 發(fā)覺是被誤導(dǎo)了:
string::c_str
public member function
const char* c_str ( ) const;
Get C string equivalent
Generates a null-terminated sequence of characters (c-string) with the same content as the string object and returns it as a pointer to an array of characters.
A terminating null character is automatically appended.
The returned array points to an internal location with the required storage space for this sequence of characters plus its terminating null-character, but the values in this array should not be modified in the program and are only guaranteed to remain unchanged until the next call to a non-constant member function of the string object.
string::data
public member function
const char* data() const;
Get string data
Returns a pointer to an array of characters with the same content as the string.
Notice that no terminating null character is appended (see member c_str for such a functionality).
The returned array points to an internal location which should not be modified directly in the program. Its contents are guaranteed to remain unchanged only until the next call to a non-constant member function of the string object.
看到以上時, 腦筋沒轉(zhuǎn)彎; 事后又忘記的差不多, 只記得有這么回事, 誤以為是從源碼看到的 |
|