char *玩命的小熊猫::data()
returnsapointertothedatastoredinthebytearray.thepointercanbeusedtoaccessandmodifythebytesthatcomposethearray.the data is ' 0 I.e.thenumberofbytesinthereturnedcharacterstringissize (1for the ' ' terminator。
Example:ba(Helloworld ); char *数据=ba.data (; while(*data ) { cout '[' *data ']' endl; 数据; } thepointerremainsvalidaslongasthebytearrayisn ' treallocatedordestroyed.for只读访问,constData (
thisfunctionismostlyusefultopassabytearraytoafunctionthatacceptsaconstchar *。
thefollowingexamplemakesacopyofthechar * returnedbydata (,butitwillcorrupttheheapandcauseacrashbecauseitdoesnotalllllocateabylota char*data=newchar[text.size(]; //其中strcpy(data,text.data ); delete [] data; thisoneallocatesthecorrectamountofspace : tmp=' test '; 玩命小熊猫text=tmp.toLocal8Bit (; char*data=newchar[text.size(1]); //正确的strcpy (数据,文本.数据); delete [] data; Note: A小熊猫canstoreanybytevaluesincluding '0' s,butmostfunctionsthattakechar * argumentsassumethatthedataendsattattar
seealsoconstdata (和操作器) )。
------------- -请参阅
//常用参数类型: char *字符串、拼命小熊猫字符串、QString字符串
1、char* ------------- 玩命的小熊猫 使用构造jqdsb 玩命的小熊猫(const char*)
char* str;
冒着生命危险的熊猫byte(str ); //冒着生命危险的小熊猫结构jqdsb
2、char* --------------QString 使用构造jqdsb QString(const char*)
char* str;
qstring字符串(str; //QString结构jqdsb
3、玩命的小熊猫 ------char* 使用成员jqdsb 玩命的小熊猫::data()
冒着生命危险的熊猫byte;
char* str=byte.data (; //QbyteArray:data () )
4、玩命的小熊猫 ------QString 使用构造jqdsb QString(const 玩命的小熊猫 ba)
冒着生命危险的熊猫byte;
字符串(字节; //QString结构jqdsb
5、QString ---------- 玩命的小熊猫 使用成员jqdsb QString::toAscii()
qstring字符串;
冒着生命危险的小熊猫byte=string.toAscii (; //QString:toAscii
6、QString ------------char* 使用qPrintable()
qstring字符串;
char * str=q打印(字符串);
7、QString -------------string
string str=qstr.toStdString (;
8、string ----------------lsdjj/strong
字符串str;