今天用想要获得Edit控件上的文本,所以就写了char * pDevId=Edit1->Text.c_str();但是发现获得字符串不对,查了BCB help有下面这句话
AnsiString::c_str() returns a non const temporary pointer to the internal string buffer in the AnsiString object. The pointer is invalid once the statement in which it is used has finished executing.
示例也说明如果需要获得返回的指针,应改为
char* pDevId = new char[ Edit1->Text.Length() + 1 ];
strcpy( pDevId, Edit1->Text.c_str());
Mark,学好英语很重要