我想是这样吧!!!
朋友们可测试一下代码!!!
void __fastcall TForm1::Button1Click(TObject *Sender)
{
AnsiString MyString;
MyString=Edit1->Text;
Edit2->Text=MyString.c_str();
String str="My love will go on!!!";
char *str1=str.c_str();
//char* __fastcall c_str() const;
Edit3->Text=str1;
}
下面是我在BCB中找到的帮助:
char* __fastcall c_str() const;
AnsiString c_str() example
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. That is,don'tdo
something like this:
char* cp = Edit1->Text.c_str();
char* cp2 = strtok( cp, " /t/n" );
// cp may no longer be valid
If you need a persistent pointer, you MUST copy the string into its own buffer:
char* cp = new char[ Edit1->Text.Length() + 1 ];
strcpy( cp, Edit1->Text.c_str() );